1.下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2.安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
3.检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
4.安装MySQL
yum install mysql-community-server
5.启动MySQL服务
service mysqld start
等同于命令:systemctl start mysqld
重启命令是:service mysqld restart
6.检查mysql 的运行状态
service mysqld status
7.修改root本地登录密码
7.1查看初始密码
grep 'temporary password' /var/log/mysqld.log
7.2用初始密码登录
mysql -uroot -p
7.3修改初始密码
set password for 'root'@'localhost'=password('Root@123456');
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误
8.授权其他机器登陆
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root@123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
9.防火墙开启3306端口
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
sudo systemctl restart firewalld.service #重启防火墙
查看所有开启的端口命令:firewall-cmd --list-ports
10.测试连接
11.设置mysql开机启动
systemctl enable mysqld
systemctl daemon-reload
12.mysql文件目录
参考文档:
https://www.linuxidc.com/Linux/2016-09/135288.htm
https://www.cnblogs.com/jimboi/p/6405560.html
https://www.cnblogs.com/silentdoer/articles/7258232.html