打开网址:https://dev.mysql.com/downloads/,选择MySQL Yum Repository 安装
2.选择 Linux 7,复制下载链接 https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
1.配置mysql8安装源,后面为刚才复制的链接
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2.安装Mysql 8.0
sudo yum --enablerepo=mysql80-community install mysql-community-server
3.启动mysql服务
sudo service mysqld start
4.查看mysql服务运行状态
service mysqld status
5.查看root临时密码
grep "A temporary password" /var/log/mysqld.log
6.更改临时密码
输入:mysql -uroot -p
在Enter password:后面输入临时密码
登录成功
输入:ALTER USER 'root'@'localhost' IDENTIFIED BY 'aafgghjaaa23@5n';
会提示:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements(密码不符合当前策略)
方案1: 设置符合策略的密码(大小写字母+数据+符号)
方案2:密码策略改简单一点
8.修改mysql 配置
vim /etc/my.cnf
修改内容
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default_authentication_plugin=mysql_native_password
character-set-server=utf8
max_allowed_packet = 500M
[mysqldump]
column-statistics=0
9.开放远程连接
进入数据库
mysql -uroot -p
use mysql;
select host, user, authentication_string, plugin from user;
查看user表的root用户Host字段是localhost,说明root用户只能本地登录,现在把他改成远程登录
update user set host='%' where user='root';
exit;
10.添加防火墙规则
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重新加载配置
firewall-cmd --reload
11.决解连接错误,因为密码加密方式不同
ALTER USER 'localhost' IDENTIFIED WITH mysql_native_password BY 'aafgghjaaa23@5n';
刷新权限生效
flush privileges;
Comments | NOTHING