2017-09-24 回答
查看现有的密码策略
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)