mysql设置密码复杂度

发布时间 2023-08-07 16:13:55作者: slnngk

环境:
OS:Centos 7
mysql:5.7.29

 

1.安装插件
mysql> INSTALL PLUGIN validate_password SONAME 'validate_password.so';
Query OK, 0 rows affected (0.04 sec)

2.查看
select plugin_name, plugin_status from information_schema.plugins where plugin_name like 'validate_password%';
show plugins;

3.查看相关参数
mysql> show variables like 'validate%';
+--------------------------------------+--------+
| 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.01 sec)

 

4.密码复杂度策略具体设置
学习完以上参数,我们就可以根据自身情况来具体设置密码复杂度策略了,
比如我想让密码至少 10 位且包含大小写字母、数字、特殊字符,则可以这样设置
set global validate_password_length = 10;

该配置重启后会实效,需要在配置文件加上
validate_password_length = 10


5.验证
mysql> grant select on db_test.* to 'hxl01'@'%' identified by 'mysql';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

mysql> grant select on db_test.* to 'hxl01'@'%' identified by 'm2Ysql4862';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

加上特殊符号
mysql> grant select on db_test.* to 'hxl01'@'%' identified by 'm#2Ysql4862';
Query OK, 0 rows affected, 1 warning (0.02 sec)