mysql用户的密码的验证(策略)问题

一、前期说明

-- 当前mysql的版本信息
[root@temp 3306]# mysql -V
mysql  Ver 14.14 Distrib 5.7.22, for linux-glibc2.12 (x86_64) using  EditLine wrapper

mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.22-log |
+------------+
1 row in set (0.00 sec)


-- 查看当前password的所有选择,里面可以看出里面没有关于密码验证的问题
mysql> show global variables like "%password%";
+---------------------------------------+-------+
| Variable_name                         | Value |
+---------------------------------------+-------+
| default_password_lifetime             | 0     |    
| disconnect_on_expired_password        | ON    |
| log_builtin_as_identified_by_password | OFF   |
| mysql_native_password_proxy_users     | OFF   |
| old_passwords                         | 0     |
| report_password                       |       |
| sha256_password_proxy_users           | OFF   |
+---------------------------------------+-------+
7 rows in set (0.00 sec)

default_password_lifetime               -- 表示默认创建用户时,用户密码永不过期,建议打开
disconnect_on_expired_password          -- 断开与过期密码的连接,建议打开
old_passwords                           -- mysql为了兼容4.1之前的客户端而保留的,建议打开


-- 查看当前运行的实例是否加载validate_password.so插件
[root@temp 3306]# mysql -uroot -p -S mysql.sock -e "show plugins;"|grep "validate_password.so"    -- 从结果可以看出没有
Enter password: 
[root@temp 3306]# 


-- 查看mysql程序中是否有validate_password.so插件
[root@temp 3306]# ll /mysql/apps/mysql/lib/plugin/validate_password.so 
-rwxr-xr-x 1 mysql mysql 204679 Mar  4  2018 /mysql/apps/mysql/lib/plugin/validate_password.so

二、安装插件

#第一种方法:
-- 在my.cnf配置文件中的[mysqld]模块中添加如下信息
plugin_dir=/mysql/apps/mysql/lib/plugin        -- 插件所在的位置
plugin_load_add=validate_password.so           -- 加载validate_password.so插件
validate_password=FORCE_PLUS_PERMANENT         -- 强制永久使用,防止用UNINSTALL PLUGIN卸载插件

-- 重启mysql服务
[root@temp 3306]# /mysql/data/3306/mysqld restart
Stop MySQL[3306]                                           [  OK  ]
Start MySQL [3306]                                         [  OK  ]

-- 查看是否
mysql> show global variables like "validate_password%";
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    | -- 表示能将密码设置成当前用户名,on表示可以,off表示不可以
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      | -- 限制密码的最小长度
| validate_password_mixed_case_count   | 1      | -- 限制密码至少要有一个大写和小写的字符
| validate_password_number_count       | 1      | -- 限制密码必须要有一个数字字符
| validate_password_policy             | MEDIUM | -- 密码安全策略的等级,LOW表示只限制长度, MEDIUM则为长度,字符,数字,大小写,特殊字符;STRONG则在之前的基础上增加字典目录
| validate_password_special_char_count | 1      | -- 限制密码中至少要有1个特殊字符
+--------------------------------------+--------+
7 rows in set (0.00 sec)


#第二种方法:
-- 在线安装插件
mysql> INSTALL PLUGIN validate_password soname 'validate_password.so';
Query OK, 0 rows affected (0.00 sec)

-- 然后在my.cnf配置文件中的[mysqld]模块中添加如下信息
plugin_dir=/mysql/apps/mysql/lib/plugin        -- 插件所在的位置
plugin_load_add=validate_password.so           -- 加载validate_password.so插件
validate_password=FORCE_PLUS_PERMANENT         -- 强制永久使用,防止人为用UNINSTALL PLUGIN卸载插件

三、创建用户进行验证

-- 当前密码的策略
01:长度最小等于8
02:至少要有一个大小写字符
03:至少要有一个数字字符
04:至少要有一个特殊字符
05:密码不能与

-- 验证 create user 'cl01'@'%' identified by "cl01";          # 错误: 密码与用户名一样
mysql> create user 'cl01'@'%' identified by "cl01";
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

-- 验证 create user 'cl01'@'%' identified by "chenlia";       # 错误:长度小于8
mysql> create user 'cl01'@'%' identified by "chenlia"; 
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

-- 验证 create user 'cl01'@'%' identified by "chenliang";     # 错误:没有大写/小写/数字/特殊字符
mysql> create user 'cl01'@'%' identified by "chenliang";
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

-- 验证 create user 'cl01'@'%' identified by "Chenliang";     # 错误:没有数字字符,没有特殊字符
mysql> create user 'cl01'@'%' identified by "Chenliang";
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

-- 验证 create user 'cl01'@'%' identified by "Chenliang01";   # 错误:没有特殊字符
mysql> create user 'cl01'@'%' identified by "Chenliang01";
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

-- 验证 create user 'cl01'@'%' identified by "Chenliang01@";  #正常:长度大于8,有大写字符,有数字字符,有特殊字符,密码不与用户名相同
mysql> create user 'cl01'@'%' identified by "Chenliang01@"; 
Query OK, 0 rows affected (0.00 sec)

疑问:当前mysql用户的密码策略已修改,那么之前我创建的用户,它的的密码不符合现在密码策略,会不会受影响呢?

回复:不会受影响

 

转载于:https://www.cnblogs.com/chenliangc/articles/11594153.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值