一.下载并安装
1.下载MySQL官方的Yum Repository
wget -i -c http://dev.mysql.com/get/mysql58-community-release-el8-2.noarch.rpm
2.安装Yum Repository
yum -y install mysql57-community-release-el7-10.noarch.rpm
3.安装mysql
yum -y install mysql-community-server
安装时报错,All matches were filtered out by modular filtering for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server
解决办法:先执行 yum module disable mysql,然后再执行yum -y install mysql-community-server
4.卸载Yum Repository
由于每次 yum 操作都会自动更新,需要把这个卸载掉
yum -y remove mysql58-community-release-el8-2.noarch
二.启动MYSQL|修改密码|开启远程访问
1.启动MYSQL
systemctl start mysqld.service
2.日志查看初始密码
grep "password" /var/log/mysqld.log
3.登陆
mysql -uroot -p
4.开启远程访问
CREATE USER 'root'@'%' IDENTIFIED BY '你的密码'; (密码最好是包含大写,小写,特殊字符,否则可能设置失败)
GRANT ALL ON *.* TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
5.防火墙添加端口3306
firewall-cmd --zone=public --add-port=3306/tcp –-permanent
重新加载 firewall-cmd --reload
若防火墙未开启,需要先启动防火墙 systemctl start firewalld
查看防火墙端口 firewall-cmd --list-ports
6.需要在控制台添加安全组,开放3306端口
例如腾讯云:
7.测试
success;
参考: