1. 下载rpm文件,用于yum安装
- 浏览器打开MySQL Yum Repository下载页
- 点击Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package 右侧的【Download】下载按钮
MySQL Community Downloads.png
- 点击左下方链接【No thanks, just start my download】,开始下载
2. 安装mysql8
- 将下载好的rpm包上传到CentOS7的/tmp目录
yum -y install /tmp/mysql80-community-release-el7-3.noarch.rpm
- yum安装MySQL服务器
yum -y install mysql-community-server
- 启动MySQL服务
systemctl start mysqld.service
- 查看服务启动之后的状态
systemctl status mysqld.service
- 找出root用户的密码
grep "password" /var/log/mysqld.log
mysql temporary password.png
- 用查出来的初始密码连接数据库
mysql -uroot -p
- 修改初始密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root_12root';
SHOW VARIABLES LIKE 'validate_password%';
set global validate_password.policy=0;
set global validate_password.length=1;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
- 设置mysql远程连接
mysql> use mysql;
mysql> update user set host="%" where user='root';
mysql> grant all privileges on test.* to root@'%';
mysql> GRANT ALL ON *.* TO 'root'@'%';
mysql> flush privileges;
- 客户端连接mysql弹窗报错:
- 原因是mysql8的加密方式规则不一样,是caching_sha2_password。需要将加密方式改成mysql_native_password
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';