修改密码报错
mysql> set -u root password=password('mysql');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-u root password=password('mysql')' at line 1
原因
原来MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格。使用了该插件会检查设置的密码是否符合当前设置的强度规则,若不满足则拒绝设置。影响的语句和函数有:create user,grant,set password,password(),old password。
解决方案
解决办法调整MySQL密码验证规则,修改 policy 和 length 的值。
1. 查看MySQL版本
[root@localhost ~]# mysql -V
mysql Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)
如图所示我这里是8.0版本的MySQL
2. MySQL 5.7 进行如下设置,即可解决问题:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
但是8.0会报错,因为8.0的变量不存在
mysql> set global validate_password_policy=0;
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
mysql> set global validate_password_length=5;
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'
第三第四步是参考讲解原因,也可以直接从第五步开始
3. 修改一个满足的密码 (如:Root_12root)
4. 修改密码后进MySQL,用命令查看 validate_password 密码验证插件是否安装。
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 5 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.17 sec)
5. MySQL 8.0 调整密码验证规则:
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=5;
Query OK, 0 rows affected (0.00 sec)
6. 重新设置密码
mysql> alter user 'root'@'localhost' identified by 'mysql';
Query OK, 0 rows affected (0.01 sec)
7. 刷新权限
flush privileges;