Centos8安装MySql8.0.20
1.下载并安装MySQL官方的 yum repository,Mysql版本8.0.20
wget -i -c http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

2.下载后直接yum安装
yum -y install mysql80-community-release-el7-3.noarch.rpm

3.安装mysql服务器
yum -y install mysql-community-server


安装完成后就会覆盖掉之前的mariadb
4.配置MySql
systemctl start mysqld.service
启动MySQL
systemctl status mysqld.service
查看MySQL启动状态

5.找出MySQL的原始密码
grep "password" /var/log/mysqld.log

其中localhost后面的就是初始密码
mysql -uroot -p
进入数据库输入之前找到的原始密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';
修改密码 new password就是新密码
6.开启MySQL远程访问
create user 'root'@'%' identified by 'password';
grant all privileges on *.* to 'root'@'%' with grant option;
其中%为任意ip 如果要设置特定ip访问 可以将%替换为ip(password为你数据库的密码)
最后再执行两条语句
flush privileges;
exit
7.为防火墙开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重启防火墙
firewall-cmd --reload
如果防火墙未开启 可以跳过此步骤