现象
mysql中操作密码相关命令时出现error
mysql> select password('admin');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
原因
mysql中有密码校验规则,通过命令查看
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)
密码校验分为三个等级:
- 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
约束项包括:
- validate_password_policy :这个参数用于控制validate_password的验证策略 0-->low 1-->MEDIUM 2-->strong。
- validate_password_length :密码长度的最小值(这个值最小要是4)。
- validate_password_number_count :密码中数字的最小个数。
- validate_password_mixed_case_count :大小写的最小个数。
- validate_password_special_char_count :特殊字符的最小个数。
- validate_password_dictionary_file :字典文件,只能是文件中的字符
处理方案
方案一
根据规则设置密码
方案二
修改规则,根据需求修改响应参数,只改validate_password_policy无效。
mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_number_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_special_char_count=0;
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 | 4 |
| validate_password_mixed_case_count | 0 |
| validate_password_number_count | 0 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 0 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
mysql> select password('admin');
+-------------------------------------------+
| password('admin') |
+-------------------------------------------+
| *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
+-------------------------------------------+
1 row in set, 1 warning (0.00 sec)