1、下载glibc版本的Mysql:https://downloads.mysql.com/archives/community/
选择Linux - Generic,之后选择需要的版本即可
mysql-5.7.14-linux-glibc2.5-x86_64.tar
将下载好的压缩包传输到虚拟机中
2、新建用户以安全方式运行进程
groupadd -r -g 306 mysql
useradd -g 306 -r -u 306 mysql
3、安装并初始化mysql
[root@localhost ~]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
[root@localhost local]# ln -sv mysql-5.7.14-linux-glibc2.5-x86_64 mysql
"mysql" -> "mysql-5.7.14-linux-glibc2.5-x86_64"
[root@localhost local]# chown -R mysql.mysql mysql/*
初始化:
注意:这时会生成一个随机密码,要保存下来
mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --
datadir=/usr/local/mysql/data
4、为mysql提供主配置文件
[root@localhost local]# cd /usr/local/mysql
[root@localhost mysql]# \cp support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
#添加如下行指定mysql数据文件的存放位置:
datadir = /usr/local/mysql/data
5、为mysql提供sysv服务脚本
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
6、启动mysql
#chkconfig --add mysqld --添加为系统服务
#chkconfig mysqld on --开机自启动
systemctl start mysqld
7、将mysql的bin目录加入PATH环境变量,编辑/etc/profile文件