查看现有的密码策略
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| 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 |
+--------------------------------------+--------+
6 rows in set (0.00 sec)
validate_password_number_count参数是密码中至少含有的数字个数,当密码策略是MEDIUM或以上时生效。
validate_password_special_char_count参数是密码中非英文数字等特殊字符的个数,当密码策略是MEDIUM或以上时生效。
validate_password_mixed_case_count参数是密码中英文字符大小写的个数,当密码策略是MEDIUM或以上时生效。
validate_password_length参数是密码的长度,这个参数由下面的公式生成
validate_password_number_count+ validate_password_special_char_count+ (2 * validate_password_mixed_case_count)
validate_password_dictionary_file参数是指定密码验证的字典文件路径。
validate_password_policy这个参数可以设为0、1、2,分别代表从低到高的密码强度,此参数的默认值为1,如果想将密码强度改若,则更改此参数为0。
创建用户时报错:
mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
报错原因:
指定的密码没有符合现有的密码策略。
解决方法:
可以按照现有策略设置密码,也可以更改密码策略。
① 按照现有密码策略指定密码mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'System#2016';
Query OK, 0 rows affected (0.16 sec)
② 更改密码策略,降低密码的验证标准
--更改密码策略为LOW
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
--更改密码长度
mysql> set global validate_password_length=0;
Query OK, 0 rows affected (0.00 sec)
--密码最小长度为4
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| 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 |
+--------------------------------------+-------+
6 rows in set (0.00 sec)
mysql> drop user 'test'@localhost;
Query OK, 0 rows affected (0.07 sec)
--创建长度为3的密码报错
mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'tes';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
--创建长度为4的密码,4为现有密码策略的最小长度
mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
Query OK, 0 rows affected (0.01 sec)