我想在MySQL中创建一个新用户,语法如下:
create user 'demo'@'localhost' identified by 'password';
但是它会返回一个错误:
您的密码不符合当前策略要求。
我试过很多密码,但都没用。我该如何解决这个问题?
我想在MySQL中创建一个新用户,语法如下:
create user 'demo'@'localhost' identified by 'password';
但是它会返回一个错误:
您的密码不符合当前策略要求。
我试过很多密码,但都没用。我该如何解决这个问题?
当前回答
因为你的密码。你可以在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文档。
其他回答
对于Laravel用户在MySQL 8.0中遇到此问题。x,添加
'modes'=> [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
到你的database.php文件如下所示:
// database.php
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env( 'DB_HOST', '127.0.0.1' ),
'port' => env( 'DB_PORT', '3306' ),
'database' => env( 'DB_DATABASE', 'forge' ),
'username' => env( 'DB_USERNAME', 'forge' ),
'password' => env( 'DB_PASSWORD', '' ),
'unix_socket' => env( 'DB_SOCKET', '' ),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
],
],
它帮我解决了问题。
用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特权;
步骤1:检查默认的身份验证插件
SHOW VARIABLES LIKE 'default_authentication_plugin';
步骤2:veryfing您的密码验证要求
SHOW VARIABLES LIKE 'validate_password%';
步骤3:使用正确的密码要求设置用户
CREATE USER '<your_user>'@'localhost' IDENTIFIED WITH '<your_default_auth_plugin>' BY 'password';
在我的例子中,当有一个错误的引用时,错误就出现了:
GRANT所有database_name。* ' user1 ' @'8.10.12.2';(用户名周围的单引号错误)
vs
GRANT所有database_name。* 'user1'@'8.10.12.2';(正确)
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%';