貌似网上也有相关介绍,不过都是各种抄袭,作为5.6比较重要的特性之一这里做一次比较详细的介绍



引入版本:MySQL 5.6.6


插件名称:validate_password


测试环境:percona 5.6.15  centos 6.4



作用:


  1,当修改mysql的账号密码时,mysql会去检查当前的是密码策略如果不符合预定义的策略则返回 ER_NOT_VALID_PASSWORD错误 ,受影响的语句


     有 CREATE USER, GRANT, and SET PASSWORD


  2,提供了一个密码安全强度的检测函数 VALIDATE_PASSWORD_STRENGTH() 从0到100依次表示从弱到强(

使用它的前提是已经加载了插件,否则只能返回0


        

mysql的密码使用什么加密算法怎么看_安全策略


 


 一,启用插件


     启用插件的方式有三种:


     1,在mysql启动的时候带--plugin-load='validate_password.so'


/etc/init.d start  --plugin-load='validate_password.so'



      然后执行show plugins;查看是否启用成功或者     


      


       

mysql的密码使用什么加密算法怎么看_mysql_02


      


      2,修改配置文件


在my.cnf文件里[mysqld]下面添加  

          plugin-load=validate_password.so 

          validate-password=FORCE_PLUS_PERMANENT   ###该参数是为了防止插件在mysql运行时的时候被卸载 

          然后重启mysql。 

        3,登陆mysql,命令行下直接安装/卸载插件插件 

            安装:INSTALL PLUGIN validate_password SONAME 'validate_password.so'; 

            卸载:UNINSTALL PLUGIN validate_password ; 

           
 注意:安装和卸载语句是不记录binlog的如果是复制环境,需要在主备库分别进行操作才可 

 二,和插件相关的参数  

       SHOW VARIABLES LIKE 'validate_password%'; 

       +--------------------------------------+--------+ 

       | Variable_name                        | Value  | 

       +--------------------------------------+--------+ 

       | validate_password_dictionary_file      |        |   ------  validate_password 插件用来验证密码的目录路径 

       | validate_password_length                   | 8      |   ------  限制密码的最小长度 

       | validate_password_mixed_case_count   | 1      |   ------  限制至少有一个大写和小写的字符 

       | validate_password_number_count           | 1      |   ------  限制必须要有一个数字字符


      | validate_password_policy                           | MEDIUM |   ------  密码安全策略LOW, MEDIUM,STRONG ,其中LOW表示只限制长度;MEDIUM 则为长度,字符,数字,大小写,特殊字符;STRONG则在之前的基础上增加字典目录


| validate_password_special_char_count | 1      |   ------  限制至少包含一个特殊字符 

       +--------------------------------------+--------+      

        

 三,创建密码实例 

      (user:root  time: 20:36 port:3306)[db: (none)]grant all on test.* to ttt@'localhost' identified by '1a'; 

      ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 

      (user:root  time: 20:37 port:3306)[db: (none)]grant all on test.* to ttt@'localhost' identified by '1a_'; 

      ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 

      (user:root  time: 20:37 port:3306)[db: (none)]grant all on test.* to ttt@'localhost' identified by '1a_A'; 

      ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 

      (user:root  time: 20:37 port:3306)[db: (none)]grant all on test.* to ttt@'localhost' identified by '1a%_A43iE'; ###可见只有满足密码安全策略的密码才可以被设置 

      Query OK, 0 rows affected (0.02 sec)


     

从5.6.10开始,如果密码的最短长度可用如下公式计算


      validate_password_number_count+ validate_password_special_char_count+ (2 * validate_password_mixed_case_count)


      如果公式计算的结果小于validate_password_length的值,那么就按validate_password_length的实际值作为限制否则以公式计算值为准。


      实例如下:

(user:root  time: 23:56 port:3306)[db: (none)]set global validate_password_length=2;  #### 设置密码最短长度为2 

       Query OK, 0 rows affected (0.01 sec) 

       (user:root  time: 23:57 port:3306)[db: (none)]grant all on *.* to lidan@'localhost' identified by '1a&'; 

       ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 

       (user:root  time: 23:58 port:3306)[db: (none)]grant all on *.* to lidan@'localhost' identified by '1a&B'; 

       Query OK, 0 rows affected (0.00 sec) 

       ---------- 

       (user:root  time: 23:58 port:3306)[db: (none)]set global validate_password_length=8; #### 设置密码最短长度为8 

       Query OK, 0 rows affected (0.00 sec) 

       (user:root  time: 00:03 port:3306)[db: (none)]set global validate_password_number_count =9;  ### 设置数字字符至少有9个 

       Query OK, 0 rows affected (0.00 sec) 

       (user:root  time: 00:03 port:3306)[db: (none)]grant all on *.* to lidan1@'localhost' identified by '123456789a_&'; ### 满足长度为8依然失败 

       ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 

       (user:root  time: 00:04 port:3306)[db: (none)]grant all on *.* to lidan1@'localhost' identified by '123456789a_T&'; ### 只有满足公式里计算长度+限制的各种策略才可以创建成功 

       Query OK, 0 rows affected (0.00 sec)





四,如何使用密码插件登陆


    1,创建MYSQL账号密码


    2,创建/删除/查看加密文件

grant all on *.* to mysqldba@'127.0.0.1' identified by '123Lume_';


       输入密码123Lume_

mysql_config_editor set --login-path=mysqldba  --host=127.0.0.1 --user=mysqldba --password


       

注意:这里必须和上面创建的密码一致否则无法登陆。


       然后你会在当前home目录看到生成了一个.mylogin.cnf的隐藏文件,如果你试图用cat .mylogin.cnf你只能看到一堆加密过的乱码


       不过你可像这样查看相关账号信息:


       

mysql的密码使用什么加密算法怎么看_mysql_03


       如果你看着不爽也可以这样删除它:

mysql_config_editor remove --login-path=mysqldba

    3,使用密码文件登陆mysql


       这个很简单了 


       

mysql的密码使用什么加密算法怎么看_ide_04


    4,适用范围


       mysql ,mysqladmin ,mysqldump 等


       


 

 ps : 安装插件后以前的不符合安全策略的旧密码依然有效,如果需要修改则需要符合密码安全策略的有效密码才可以修改成功。


   吐槽: mysql 5.6都出来N久了,xtrabackup居然还不支持,这叫人情何以堪!    


        


   参考:


    http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html     http://dev.mysql.com/doc/refman/5.6/en/validate-password-plugin.html#validate-password-plugin-installation