MySQL8修改root密码报错 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

23-07-27 11:46 字数 3599 阅读 2713 已编辑

本地的MySQL,改不了root密码,报错如下。

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

字面意思,输入的密码不符合当前的密码策略

查看密码验证策略

SHOW VARIABLES LIKE 'validate_password%';

+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| 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.01 sec)

解决办法

SET GLOBAL validate_password.LENGTH = 4;
SET GLOBAL validate_password.policy = 0;
SET GLOBAL validate_password.mixed_case_count = 0;
SET GLOBAL validate_password.number_count = 0;
SET GLOBAL validate_password.special_char_count = 0;
SET GLOBAL validate_password.check_user_name = 0;
ALTER USER 'root'@'%' IDENTIFIED BY 'root';
FLUSH PRIVILEGES;

关于 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 的取值:

0/LOW:只验证长度;

1/MEDIUM:验证长度、数字、大小写、特殊字符;

2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;

6、validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;

7、validate_password.check_user_name 校验密码和用户名是否相同

我的错就是第七条 validate_password.check_user_name影响的,我要把密码修改成root和用户名一样。但是这个参数值是ON。所以无论怎么修改其他的参数,都会报错。 最后放上官方文档里对这个参数的解释

When validate_password.check_user_name is enabled, it has these effects:

Checking occurs in all contexts for which validate_password is invoked, which includes use of statements such as ALTER USER or SET PASSWORD to change the current user's password, and invocation of functions such as VALIDATE_PASSWORD_STRENGTH().

The user names used for comparison are taken from the values of the USER() and CURRENT_USER() functions for the current session. An implication is that a user who has sufficient privileges to set another user's password can set the password to that user's name, and cannot set that user's password to the name of the user executing the statement. For example, 'root'@'localhost' can set the password for 'jeffrey'@'localhost' to 'jeffrey', but cannot set the password to 'root.

Only the user name part of the USER() and CURRENT_USER() function values is used, not the host name part. If a user name is empty, no comparison occurs.

If a password is the same as the user name or its reverse, a match occurs and the password is rejected.

User-name matching is case-sensitive. The password and user name values are compared as binary strings on a byte-by-byte basis.

If a password matches the user name, VALIDATE_PASSWORD_STRENGTH() returns 0 regardless of how other validate_password system variables are set.

翻译

启用 validate_password.check_user_name 后,会产生以下效果:

在调用 validate_password 的所有情况下都会进行检查,包括使用 ALTER USER 或 SET PASSWORD 等语句更改当前用户的密码,以及调用 VALIDATE_PASSWORD_STRENGTH() 等函数。

用于比较的用户名取自当前会话的 USER() 和 CURRENT_USER() 函数值。这意味着,拥有足够权限设置其他用户密码的用户可以将密码设置为该用户的名称,而不能将该用户的密码设置为执行语句的用户的名称。例如,"root'@'localhost "可以将 "jeffrey'@'localhost "的密码设置为 "jeffrey",但不能将密码设置为 "root"。

只使用 USER() 和 CURRENT_USER() 函数值中的用户名部分,而不使用主机名部分。如果用户名为空,则不会进行比较。

如果密码与用户名相同或相反,则会发生匹配,密码将被拒绝。

用户名匹配区分大小写。密码和用户名值以二进制字符串的形式逐字节进行比较。

如果密码与用户名匹配,无论其他 validate_password 系统变量如何设置,VALIDATE_PASSWORD_STRENGTH() 都会返回 0。

2人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论