修改Mysql密码策略
Mysql5.6.6对密码强度进行了加强,引入了validate_password插件,如果密码不符合要求,创建帐号会提示错误:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
Command-Line Format | --validate-password-policy=value |
---|---|
System Variable | validate_password_policy |
Scope | Global |
Dynamic | Yes |
Type | Enumeration |
Default Value | 1 |
Valid Values | 0 1 2 |
The password policy enforced by validate_password
. This variable is unavailable unless validate_password
is installed.
validate_password_policy
affects how validate_password
uses its other policy-setting system variables, except for checking passwords against user names, which is controlled independently by validate_password_check_user_name
.
The validate_password_policy
value can be specified using numeric values 0, 1, 2, or the corresponding symbolic values LOW
, MEDIUM
, STRONG
. The following table describes the tests performed for each policy. For the length test, the required length is the value of the validate_password_length
system variable. Similarly, the required values for the other tests are given by other validate_password_*
xxx*
variables.
Policy | Tests Performed |
---|---|
0 or LOW |
Length |
1 or MEDIUM |
Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG |
Length; numeric, lowercase/uppercase, and special characters; dictionary file |
(1) 设置密码策略为低
mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| 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> create user abcd@'localhost' identified by '1234';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set GLOBAL validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set GLOBAL validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
(2) 创建用户
mysql> create user abcd@'localhost' identified by '1234';
Query OK, 0 rows affected (0.00 sec)
温馨提示: 也可以在配置文件中修改
[root@server ~]# vi /etc/my.cnf
validate_password_policy = 0
validate_password_length = 4