- 1、 安装社区套件yum源地址:
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- 2、安装MySQL服务:
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
- 3、启动 MySQL
systemctl start mysqld.service
- 4、查看MySQL启动状态:
systemctl status mysqld.service
- 5、找出MySQL的登录密码
grep "password" /var/log/mysqld.log
- 6、以root用户身份登陆MySQL:
mysql -uroot -p
输入上面找出的 MySQL 密码
- 7、更改密码弱口令设置,设置简单密码
set global validate_password_policy=0;
set global validate_password_policy=0;
- 8、设置密码(新密码为:new-password)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password';
- 9、将MySQL使可以外部连接:(new-password为你刚刚设置的密码)
Grant all privileges on *.* to 'root'@'%' identified by 'new-password' with grant option;
刷新,立即生效
flush privileges;
- 10、因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉
yum -y remove mysql57-community-release-el7-10.noarch
- 11、开放数据库的3306默认端口:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
- 此时就可以从外部连接MySQL了