方法一:写入配置文件,重启MySQL实例[mysqld]plugin-load=validate_password.so方法二:在实例运行中使用install plugin命令加载插件INSTALL PLUGIN validate_password SONAME 'validate_password.so';二、验证插件加载情况mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS -> WHERE PLUGIN_NAME LIKE 'validate%';+-------------------+--------------------+| PLUGIN_NAME | PLUGIN_STATUS |+-------------------+--------------------+| validate_password | ACTIVE |+-------------------+--------------------+1 row in set (0.00 sec)三、查看默认密码策略默认的密码强度级别是中等(MEDIUM),即密码不能少于8位,且要包含数字、大小写字母、特殊符号至少各一个:mysql> show variables like '%validate_password%';+--------------------------------------+--------+| Variable_name | Value |+--------------------------------------+--------+| validate_password_check_user_name | OFF | #设为 ON 时密码中不允许包含用户名| validate_password_dictionary_file | | #用于密码验证的字典文件路径,仅在密码验证级别为STRONG时生效| validate_password_length | 8 | #限制密码最短长度不得少于8位| validate_password_mixed_case_count | 1 | #密码中大小写字母的最少个数| validate_password_number_count | 1 | #密码中数字的最少个数| validate_password_policy | MEDIUM | #设置密码验证级别| validate_password_special_char_count | 1 | #密码中特殊符号的最少个数+--------------------------------------+--------+四、测试密码插件的效果在新设置不符合密码策略规则的密码时会报错,提示不满足密码策略要求:mysql> create user hy@'192.168.1.%' identified by 'xxxxxx123';ERROR 1819 (HY000): Your password does not satisfy the current policy requirements设置符合策略的复杂密码后可以成功执行:mysql> create user hy@'192.168.1.%' identified by '1qaz@WSX';Query OK, 0 rows affected (0.00 sec)mysql> select user,host,authentication_string from mysql.user;+-----------+-------------+-----------------------------------------------------------+| user | host | authentication_string |+-----------+-------------+-----------------------------------------------------------+| root | localhost | *6AF239DABA5FB2A794AFA158646426FC1E9A5742 || mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE || hy | 192.168.1.% | *58319282EAB9E38D49CA25844B73DA62C80C2ABC |+-----------+-------------+-----------------------------------------------------------+
新闻热点
疑难解答