环境说明:centos7.3
1.卸载mysql
(过程略)
2.卸载mariadb
由于有些版本自带的有mariadb(本质是mysql,只是名字不一样而已),需要先检查是否有mariadb,若有则卸载
[root@iZuf6ih01h8fzeziddwkfdZ opt]#rpm -qa|grep -i mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
3.下载mysql5.7
进入网址:https://dev.mysql.com/downloads/mysql/
选择MySQL Community Server 5.7
操作系统选择Red Hat Enterprise Linux/Oracle Linux
OS Version选择Red Hat Enterprise Linux7/Oracle Linux(x86,64-bit)
将页面往下拉,下载以下四个rpm文件
mysql-community-client-5.7.24-1.el7.x86_64.rpm
mysql-community-server-5.7.24-1.el7.x86_64.rpm
mysql-community-common-5.7.24-1.el7.x86_64.rpm
mysql-community-libs-5.7.24-1.el7.x86_64.rpm
3.安装mysql
1.安装依赖包
1.1安装依赖libaio
yum -y install libaio.so.1
1.2安装依赖net-tools
yum install net-tools
2.执行rpm文件
在/usr/local/目录下,创建目录mysql5.7src。将mysql的rpm文件拷贝至/usr/local/mysql5.7src目录下
依次执行(几个包有依赖关系,所以执行有先后)下面命令安装
[root@localhost mysql5.7src]# rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm
[root@localhost mysql5.7src]# rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm
[root@localhost mysql5.7src]# rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm
[root@localhost mysql5.7src]# rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm
1.初始化数据库
[root@localhost mysql5.7src]#mysqld --initialize --user=mysql
2.启动数据库
[root@localhost mysql5.7src]#systemctl start mysqld.service
3.查看初始密码
[root@localhost mysql5.7src]#vi /var/log/mysqld.log
使用初始密码登录数据库
[root@localhost mysql5.7src]mysql -uroot -pg11l/gKzjE_j
4.登录成功后修改密码
mysql>SET PASSWORD = PASSWORD('123456'); #设置密码为123456
(此时系统会提示密码不符合复杂性要求,设置密码失败)
mysql>set global validate_password_policy=0; #设置基于长度判断密码复杂性
mysql>set global validate_password_length=4; #设置长度限制最小值为4
mysql> SET PASSWORD = PASSWORD('123456'); #设置密码为123456
( 这一次密码修改成功 )
mysql>q;
5.使用修改后的密码登录,授予root用户远程登录权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
参考地址 https://www.cnblogs.com/pythonal/p/6141516.html