1、卸载系统自带的 mariadb-lib
1)#rpm -qa|grep mariadb
2)# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps
3)#rpm -qa|grep mariadb
2、安装 wget
#yum install wget -y
3、下载mysql5.7.16 rpm安装包,官网最新的mysql安装包是mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar下载地址
#wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
4、解压
#tar -xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
5、依次安装:
1)#rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
2)#rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
3)#rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
4)#rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm
第4)步的时候可能会报错:
warning: mysql-community-server-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
ibaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
net-tools is needed by mysql-community-server-5.7.16-1.el7.x86_64(可能没有这个)
需要安装:
1)libaio-0.3.107-10.el6.x86_64.rpm
1)#wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
2)#rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm
2)yum install net-tools -y
5)继续安装(如果第4)步没有错,就不用)
#rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm
6、数据库初始化
1)#mysqld --initialize --user=mysql
2)找密码,红色区域
1)# cat /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: )1r3gi,hjgQa
7、现在启动mysql数据库
1)#systemctl start mysqld.service
2)# mysql -uroot -p
8、修改密码、权限
1)#ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
2)#GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
3)#flush privileges;
9、开放端口
1)#firewall-cmd --zone=public --add-port=3306/tcp --permanent
2)#firewall-cmd --reload
10、完成
附:
启动/停止/重启MySQL
1)启动:service mysqld start
2)停止:service mysqld stop
3)重启:service mysqld restart
参考:https://www.cnblogs.com/pythonal/p/6141516.html