1.运行以下命令更新YUM源
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
2.运行以下命令安装MySQL
如果您使用的操作系统内核版本为el8,可能会提示报错信息No match for argument。您需要先运行命令yum module disable mysql禁用默认的MySQL模块,再安装MySQL。
yum -y install mysql-community-server --nogpgcheck
3.运行以下命令查看MySQL版本号
mysql -V
返回结果如下所示,表示MySQL安装成功。
mysql Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using EditLine wrapper
4.运行以下命令启动MySQL
systemctl start mysqld
5.依次运行以下命令设置开机启动MySQL
systemctl enable mysqld
systemctl daemon-reload
6.运行以下命令查看/var/log/mysqld.log文件,获取并记录root用户的初始密码
grep 'temporary password' /var/log/mysqld.log
出现下面内容
2022-12-20T19:42:35.250992Z 1 [Note] A temporary password is generated for root@localhost: _N!G-o8LFv=d
7.运行以下命令配置MySQL的安全性。
mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: #输入上一步获取的root用户初始密码
The existing password for the user account root has expired. Please set a new password.
New password: #输入新密码。长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号包含()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
Re-enter new password: #确认新密码。
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100 #返回结果包含您设置的密码强度。
Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #您需要输入Y以确认使用新密码。
#新密码设置完成后,需要再次验证新密码。
New password:#再次输入新密码。
Re-enter new password:#再次确认新密码。
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :Y #您需要输入Y,再次确认使用新密码。