安装Mysql
运行以下命令更新YUM源。
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
运行以下命令安装MySQL。
说明 如果您使用的操作系统内核版本为el8,可能会提示报错信息No match for argument。您需要先运行命令yum module disable mysql禁用默认的mysql模块,再安装MySQL。
yum -y install mysql-community-server
运行以下命令查看MySQL版本号。
mysql -V
返回结果如下所示,表示MySQL安装成功。
mysql Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using EditLine wrapper
运行以下命令启动MySQL。
systemctl start mysqld
运行以下命令设置开机启动MySQL。
systemctl enable mysqld systemctl daemon-reload
配置mysql
运行以下命令查看/var/log/mysqld.log文件,获取并记录root用户的初始密码。
grep 'temporary password' /var/log/mysqld.log
返回结果如下:
2016-12-13T14:57:47.535748Z 1 [Note] A temporary password is generated for root@localhost: p0/G28g>lsHD
说明 下一步重置root用户密码时,会使用该初始密码。
运行以下命令配置MySQL的安全性。
mysql_secure_installation
安全性的配置包含以下五个方面:
-
- 重置root账号密码,必须满足密码复杂度
Enter password for user root: #输入上一步获取的root用户初始密码 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 #是否更改root用户密码,输入Y New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/ 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删除匿名用户账号。
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #是否删除匿名用户,输入Y Success.
输入Y禁止root账号远程登录。
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y Success.
输入Y删除test库以及对test库的访问权限。
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y - Dropping test database... Success.
输入Y重新加载授权表。
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y Success. All done!
修改密码复杂度
mysql> show variables like ‘%validate_password%’;
默认的情况下,密码策略是这样的, 默认8位长度并且要大小写。
+--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +--------------------------------------+--------+ 7 rows in set (0.00 sec)
mysql> set global validate_password_policy=0; # 关闭密码复杂性策略
mysql> set global validate_password_length=1; # 设置密码复杂性要求密码最低长度为1
再次查看
mysql> show variables like '%validate_password%' -> ; +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 4 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | LOW | | validate_password_special_char_count | 1 | +--------------------------------------+-------+ 7 rows in set (0.00 sec)
修改密码:
mysql> alter user ‘root’@’localhost’ identified by ‘1234’;
或者 退出Mysql命令行,使用
mysqladmin -uroot -p password 1234
输入原先的密码即可修改
暂无评论内容