当前位置: 代码迷 >> 综合 >> ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
  详细解决方案

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

热度:36   发布时间:2024-01-24 13:30:34.0

问题:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123Abc!';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

解决方案:

以上是MySQL密码策略的问题

方案:

设置一个符合其策略的密码。默认密码的长度最小值为 8 ,由 大/小写字母各一个 + 阿拉伯数字一个 + 特殊字符一个

扩展:

1)查看 mysql 初始的密码策略:

SHOW VARIABLES LIKE 'validate_password%';

执行前需要先设置一个符合其策略的新密码,不然会报错:
mysql> SHOW VARIABLES LIKE ‘validate_password%’;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

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.02 sec)

2)根据需求设置密码的验证强度等级。此处示例设置 validate_password_policy 的全局参数为 LOW ,这样密码策略就只会验证密码的长度了:

set global validate_password_policy=LOW; 
mysql> set global validate_password_policy=LOW; 
Query OK, 0 rows affected (0.00 sec)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             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.01 sec)

3)默认密码长度为 8 ,按需设置长度,这里设置validate_password_length 的全局参数为 6 :

set global validate_password_length=6;

4)现在可以为 mysql 设置简单密码了,只要满足六位的长度即可:

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; 

mysql 密码策略相关参数说明:
1)validate_password_length 固定密码的总长度;
2)validate_password_dictionary_file 指定密码验证的文件路径;
3)validate_password_mixed_case_count 整个密码中至少要包含大/小写字母的总个数;
4)validate_password_number_count 整个密码中至少要包含阿拉伯数字的个数;
5)validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;
关于 validate_password_policy 的取值:
LOW:只验证长度;
MEDIUM:验证长度、数字、大小写、特殊字符;
STRONG:验证长度、数字、大小写、特殊字符、字典文件;
6)validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;

  相关解决方案