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服務(wù)器
yum -y install mysql-community-server
安裝完成后就會(huì)覆蓋掉之前的mariadb
4.配置MySql
systemctl start mysqld.service
啟動(dòng)MySQL
systemctl status mysqld.service
查看MySQL啟動(dòng)狀態(tài)
5.找出MySQL的原始密碼
grep "password" /var/log/mysqld.log
其中l(wèi)ocalhost后面的就是初始密碼
mysql -uroot -p
進(jìn)入數(shù)據(jù)庫輸入之前找到的原始密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';
修改密碼 new password就是新密碼
6.開啟MySQL遠(yuǎn)程訪問
create user 'root'@'%' identified by 'password';
grant all privileges on *.* to 'root'@'%' with grant option;
其中%為任意ip 如果要設(shè)置特定ip訪問 可以將%替換為ip(password為你數(shù)據(jù)庫的密碼)
最后再執(zhí)行兩條語句
flush privileges;
exit
7.為防火墻開放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重啟防火墻
firewall-cmd --reload
如果防火墻未開啟 可以跳過此步驟