1:执行修改用户的密码时,一直报错:即修改密码命令:
mysql> alter user 'root'@'localhost' identified by '123456';
报错如下:
mysql> alter user 'root'@'localhost' identified by '123456';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
2:百度查找说是设置:MySQL的密码策略,即命令如下:
set global validate_password_policy=LOW;
set global validate_password_length=6;
mysql> set global validate_password_length=6;
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'
分别报错如下,意思是不知道哪个字段:
mysql> set global validate_password_policy=LOW;
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
3:然后查找了 MySQL密码初始设置策略,发现字段不对:
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.02 sec)
然后有分别重新设置了一下:
备注:validate_password.policy=LOW 设置为LOW值意思是:只验证密码的长度。及长度为6(global validate_password.length=6; )
mysql> set global validate_password.policy=LOW;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=6;
Query OK, 0 rows affected (0.00 sec)
4:执行以下命令:如果没有报错。那就ok了。如果报如图错误,请继续往下看;
alter user 'root'@'localhost' identified by '123456';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
报上图错误有可能是你执行了:以下的命令(第三条)
mysql> use mysql;
mysql> select host,user,authentication_string,plugin from user;
mysql> update user set host='%' where user='root';
mysql> flush privileges;
因此,你需要换执行命令,就OK了:
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
第3步扩展:
(1):validate_password.dictionary_file 指定密码验证的文件路径;
(2):validate_password.length 密码固定的长度;
(3):validate_password.mixed_case_count 密码中至少包含大小写字母的个数;
(4):validate_password.number_count 密码中至少包含的数字个数;
(5):validate_password.special_char_count 密码中至少包含特殊字符的个数;
(6):validate_password.policy 密码强度验证,默认为 MEDIUM;
关于 validate_password.policy 的取值:
0/LOW:只验证长度;
1/MEDIUM:验证长度、数字、大小写、特殊字符;
2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;
标签:set,MySQL5.7,用户,密码,mysql,policy,validate,password
From: https://www.cnblogs.com/Xneat/p/18369287