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

**URL:** <https://www.shiqidu.com/t/topic/798>\
**Category:** 开发调优\
**Tags:** MySQL\
**Created:** [2023 年7 月 27 日 03:46 UTC](https://www.shiqidu.com/t/topic/798 "2023-07-27T03:46:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![caojie](https://www.shiqidu.com/user_avatar/www.shiqidu.com/caojie/32/465_2.png) [@caojie](https://www.shiqidu.com/u/caojie)\
发布日期： [2023 年7 月 27 日 03:46 UTC](https://www.shiqidu.com/t/topic/798/1 "2023-07-27T03:46:40Z")

</div>

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

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

```

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

查看密码验证策略

```mysql
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)

```

解决办法

```mysql
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。
