我想在MySQL中创建一个新用户,语法如下:

create user 'demo'@'localhost' identified by 'password';

但是它会返回一个错误:

您的密码不符合当前策略要求。

我试过很多密码,但都没用。我该如何解决这个问题?


当前回答

在我的例子中,当有一个错误的引用时,错误就出现了:

GRANT所有database_name。* ' user1 ' @'8.10.12.2';(用户名周围的单引号错误)

vs

GRANT所有database_name。* 'user1'@'8.10.12.2';(正确)

其他回答

mysql> SET GLOBAL validate_password.policy = 0;

因为你的密码。你可以在MySQL客户端中使用以下查询查看密码验证配置指标:

SHOW VARIABLES LIKE 'validate_password%';

输出应该是这样的:

+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | ON    |
| validate_password.dictionary_file    |       |
| validate_password.length             | 6     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 1     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+

然后可以将密码策略级别设置低一些,例如:

SET GLOBAL validate_password.length = 6;
SET GLOBAL validate_password.number_count = 0;

查看MySQL文档。

SHOW VARIABLES LIKE 'validate_password%';

mysql> SET GLOBAL validate_password.length = 6;
mysql> SET GLOBAL validate_password.number_count = 0;
mysql> SET GLOBAL validate_password.policy=LOW;
SHOW VARIABLES LIKE 'validate_password%';


this information is important to all answers above : When you restart mysql server all policy config will be RESET and will be LOST, so to make your policy configuration PERSISTENT, you should follow these instructions: (tested on ubuntu server version 20.10)

用mysql应用这些变化后,洪阮回答 Sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf 加上最后一行:

[mysqld]
#
# * Basic Settings
#
..
..
..
validate_password.policy = LOW   # <== this line
..
..
# IMPORTANT notes: 
# - you can add more policy commands each by your needs.
# - notice the "." before "policy" , in some mysql versions is "_" , so be aware of that.

保存文件并重新启动mysql server: sudo service mysql restart 连接并检查配置的持久性: Sudo mysql -u your_username -p 显示像"validate_pass%"这样的变量; 结果应该是这样的:

+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | ON    |
| validate_password.dictionary_file    |       |
| validate_password.length             | 6     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 0     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+

我希望这能帮助到人们。

编辑:感谢@ahmednawazbutt:不要忘记FLUSH特权;

请设置满足7条MySql验证规则的密码

例如:- d_VX>N(“xn_BrD2y

让验证标准更简单一点可以解决这个问题

SET GLOBAL validate_password_length = 6;
SET GLOBAL validate_password_number_count = 0;

但建议使用强密码是正确的解决方案