8.X版本:
#查看密码策略 show variables like ‘%validate_password.policy%‘; show variables like ‘%validate_password.length%‘; #修改密码策略 set global validate_password.policy=0; #设置为弱口令 set global validate_password.length=1; #密码最小长度为1
57版本:
#查看密码策略 show variables like ‘%validate_password_policy%‘; show variables like ‘%validate_password_length%‘; #修改密码策略 set global validate_password_policy=0; set global validate_password_length=1;
密码策略的所有参数:
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.01 sec)
validate_password.policy(校验规则),取值范围[0,1,2],默认值1。0(LOW):只校验长度;1(MEDIUM):校验长度、大小写和特殊字符;2(STRONG):校验长度、大小写、特殊字符和dictionary_file
更多参数说明查看:https://dev.mysql.com/doc/refman/8.0/en/validate-password-options-variables.html
注意:
validate_password是已插件的形式安装在mysql中的,关于该插件的更多介绍访问:https://dev.mysql.com/doc/refman/8.0/en/validate-password.html
docker安装的mysql是没有validate_password插件的。另外,根据官网介绍,validate_password已经被废弃,未来会被移除。
作为替代方案,component_validate_password组件会被启用:
mysql -u root -p # 登陆mysql,也可以用navicat工具登陆 INSTALL COMPONENT ‘file://component_validate_password‘; # 安装组件 UNINSTALL COMPONENT ‘file://component_validate_password‘; # 卸载组件
上面的命令可直接运行的,该组件是默认存在的,可通过命令查看插件或组件目录:
show variables like ‘plugin_dir‘; # 查看mysql插件或组件目录