Ubuntu14.04 安装 mysql压缩包版(glibc)

Ubuntu14.04 安装 mysql压缩包版(glibc)

首先贴官方的安装指南: https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

一、下载mysql

1.进入清华的镜像站 https://mirror.tuna.tsinghua.edu.cn/
2.下载5.7版本 mysql/downloads/MySQL-5.7/
3.找到文件 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
4.解压并重命名至/usr/local/mysql

tar -zxf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /usr/local
mv /usr/local/mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
二、配置mysql

1.为mysql创建用户

groupadd mysql
useradd -r -g mysql mysql

2.将/usr/local/mysql/的所有者设为mysql用户

chown -R mysql.mysql /usr/local/mysql

3.配置mysql的config文件

mkdir /etc/mysql
touch /etc/mysql/my.cnf
vim /etc/mysql/my.cnf

在my.cnf文件中写入下列内容

[mysql]
# 设置mysql客户端默认字符集 
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock 
[mysqld]
#skip-name-resolve 
#设置3306端口 
port = 3306
socket=/usr/local/mysql/mysql.sock 
# 设置mysql的安装目录 
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录 
datadir=/usr/local/mysql/data
# 允许最大连接数 
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集 
character-set-server=utf8
# 创建新表时将使用的默认存储引擎 
default-storage-engine=INNODB
#lower_case_table_name=1 
max_allowed_packet=16M
#跳过权限认证
#skip-grant-tables

4.初始化mysql

sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql

5.这里由于缺少libaio包会出现错误的提示
error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
对于linux系统分为 RedHat系列和Debian系列,其中 RedHat系列包括的系统有:Redhat、Centos、Fedora等,而Debian系列包括:Debian、Ubuntu等。他们的包管理器是不相同的,对于RedHat系列,使用yum包管理器,而对于Debian,使用apt包管理器

对于Ubuntu,则安装libaio的命令为sudo apt-get install libaio, 提示找不到libaio, 应为在apt包管理器上libaio的名字为libaio1, 所以正确的命令应该为

sudo apt-get update
sudo apt-get install libaio1

为了加快下载速度,可以更改apt的源
1.备份源文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

2.更改源

sudo vim /etc/apt/sources.list

将里面的内容全部删除,添加下面的内容

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse 

6.添加mysql启动脚本软链接

$ sudo ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server

7.将mysql的相关启动文件加入环境变量 vim /etc/profile 中加入下面内容

# mysql
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin:$PATH:$MYSQL_HOME/support-files

然后source /etc/profile
8.添加开机启动守护进程sudo update-rc.d mysql.server defaults

三、启动MySQL

1.启动MySQL

/etc/init.d/mysql.server start

2.ps检查进程ps -aux |grep mysql
3.用root用户登录 mysql -u root -p,正常情况会提示你让你设置初始密码
然后我在这里踩了一个坑
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
解决办法: 首先设置无权限验证登录mysql,在mysql内修改root用户的密码
首先vim /etc/mysql/my.cnf中选择跳过权限认证
然后mysql进入shell命令界面

use mysql; 		# 使用mysql数据库
UPDATE user SET authentication_string=password("123456") WHERE user='root';

在mysql 5.7版本之间 命令应该为UPDATE user SET password=password("123456") WHERE user='root';
但是在mysql5.7之后,password字段不再使用了,应该改为authentication_string

4.当关闭mysql再次运行登录入mysql后,无论运行什么shell命令,比如show databases;都会提示
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement
解决办法: 重新设置mysql的root用户的密码

set password=password('new password'); #这里mysql5.7版本password字段又可以使用了 也不知道为什么
flush privileges;

到这里mysql已经安装配置完成了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值