MySQL8的密码策略

解释: 由于valiadte_password策略。密码强度需要非常高,所以有时候密码都无法成功修改。了解完下面变量就能解决了。


  • validate_password.policy:密码策略,检查用户的密码。

    • 0:(Low)密码长度最少8个字符
    • 1:(Mediumpolicy)至少包含1个数字,1个小写字母,1个大写字母和1个特殊字符组成(默认值)
    • 2:(Strongpolicy)长度为4或更长的密码子字符串不得与字典文件中的单词匹配
  • validate_password.length:需要密码最小字符数,默认为8

  • validate_password.number_count:需要密码的最小数字字符数,默认为1

  • validate_password.mixed_case_count:需要密码的小写和大写的最小字符数,默认为1

  • validate_password.special_char_count:需要密码的特殊字符的最小字符数,默认为1

  • validate_password.dictionary_file:用于检查密码的字典文件的路径名,默认没有


所以,如果出现报错:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,你可以:

Set Persist validate_password.policy = 0

只要你的密码长度不低于8个字符就行了,如果密码长度觉得还是长了,你可以:

Set Persist validate_password.length = 0

这样,你的长度是0,但注意,最小字符数不能低于以下表达式的值:

validate_password.number_count 
+ validate_password.special_char_count 
+ (2 * validate_password.mixed_case_count)

所以你的密码最小长度是4位,然后你可以直接查看:

mysql> Show Variables Like 'validate_password.%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | ON    |
| validate_password.dictionary_file    |       |
| validate_password.length             | 4     |  <-- 尽管你设置的是0,但最小还是4
| 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.02 sec)


密码强度评估:1 ~ 100

mysql> select validate_password_strength('Password!');
+-----------------------------------------+
| validate_password_strength('Password!') |
+-----------------------------------------+
|                                      50 |
+-----------------------------------------+
1 row in set (0.00 sec)

下面是官方的一段原话:英文好的可以看看

In MySQL 8.0.4, the validate_password plugin was reimplemented as the validate_password component. The validate_password plugin is deprecated and will be removed in a future version of MySQL. Consequently, its options are also deprecated and will be removed. MySQL installations that use the plugin should make the transition to using the component instead.



以上资料参考官方文档:6.4.3密码验证组件

原文地址:https://www.cnblogs.com/liuhedong/p/11131693.html