1.MySQL版本选择参考文章
2.到MySQL官网下载 https://dev.mysql.com/downloads/mysql/,选择版本如下
安装参考文章点击打开链接
解压
tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local/
mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
创建mysql用户组
groupadd mysql
创建mysql用户(用户名:组名)
useradd -r -g mysql -s /bin/false mysql
cd /usr/local/mysql
chown -R mysql:mysql ./
安装
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
执行安装命令,报错信息如下
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决办法:yum install -y libaio
继续执行安装命令,报错信息如下
./bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
解决办法:yum -y install numactl
继续执行安装命令,终于不报错了,执行结果如下
注意,此刻mysql为我们生成了一个随机密码,如上图。最好先记录下这个随机密码,后面登录会使用到。
启动mysql服务
./support-files/mysql.server start
报错信息如下
Starting MySQL.2018-03-09T14:01:52.084978Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
ERROR! The server quit without updating PID file (/var/lib/mysql/cslave-112.pid).
按照下面文章的解决思路都没有搞定,最后发现是character-set-server=utf8 错写成了utf-8,坑了。
http://blog.csdn.net/fuck487/article/details/77319640?locationNum=1&fps=1
/etc/my.cnf 配置文件如下
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_names = 1
character-set-server=utf8
collation-server=utf8_general_ci
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/usr/local/mysql/mysql.sock
default-character-set=utf8
终于启动成功了!
将mysql进程放入系统进程中
cp support-files/mysql.server /etc/init.d/mysqld
这样就可以使用如下命令重启mysql了
service mysqld restart
配置mysql环境变量
使用上面生成的随机密码登录
错误信息显示,我们必须重置密码,这里我们重置为rootroot
alter user 'root'@'localhost' identified by 'rootroot';
设置远程登录
use mysql;
update user set user.host='%' where user.user='root';
flush privileges;
查看字符集
show variables like '%char%';