当我们设置数据库密码级别的时候

mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=4;

出现这样的报错:

mysql> set global validate_password_policy=0;
ERROR 1193 (HY000): Unknown system variable ‘validate_password_policy’

解决方案是:
打开/etc/my.cnf,然后在[mysqld]的下方加入如下代码:

plugin-load-add=validate_password.so
validate-password=FORCE_PLUS_PERMANENT

然后重启mysqld服务,如下:

systemctl restart mysqld.service

最后登录MySQL,刷新权限

flush privileges;

查看安全策略:

mysql> SHOW VARIABLES LIKE ‘validate_password%’;
±————————————-±——-+
| Variable_name | Value |
±————————————-±——-+
| validate_password_check_user_name | OFF |
| 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 |
±————————————-±——-+