若没有wget 命令:yum install -y wget
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源是否安装ok
yum repolist enabled | grep "mysql.-community."
4.安装MySQL
yum install mysql-community-server
5.启动MySQL服务
systemctl status mysqld 查看MySQL启动状态
systemctl start mysqld 启动MySQL服务
6.开机启动设置 (开机自启动)
systemctl enable mysqld
systemctl daemon-reload
7.修改root默认密码
a.查看MySQL初始化的临时密码
grep 'temporary password' /var/log/mysqld.log
在/var/log/mysqld.log文件中给root生成了一个默认密码,长这样:HR!Tz5GpiCAA
b.修改密码
先连接到MySQL,进入命令行:
alter user 'root'@'localhost' identified by 'abc123456';
遇到问题:Your password does not satisfy the current policy requirements
这是因为不符合当前的密码设置策略:
-
查看当前密码策略:show variables like 'validate_password%';
-
修改密码策略:
1.设置密码的验证强度等级
validate_password_policy
set global validate_password_policy=LOW;
2.密码默认长度为8,修改为9:
set global validate_password_length=9;
或者:可以直接去修改配置文件
/etc/my.cnf
添加validate_password_policy
配置
8.重启MySQL服务
systemctl restart mysqld
启动MySQL失败可能原因
-
3306 端口被占用
可以查看MySQL运行日志,检查启动失败问题
tail /var/log/mysqld.log
参考视频地址: