MYSQL5.7修改密码强度策略

---恢复内容开始---

在MySQL5.6.6之后,ORACLE更新了mysql密码强度必须要使用大小写数字符号来设置密码,但是有时候这样还是很不方便的.所以记录一篇如何修改mysql密码强度的博文.

安装mysql之后启动服务,第一次登录在日志中去找到临时密码

  [root@localhost ~]# grep "password" /var/log/mysqld.log
  2019-10-08T11:02:46.164080Z 1 [Note] A temporary password is generated for root@localhost: YDCvJr;ly3Oq

使用临时密码进行登录

  mysql -uroot -pYDCvJr;ly3Oq

登录后需要先修改密码才能进行其他操作.

使用ALTER USER username@hostname IDENTIFIED BY "new password"; 修改密码

  ALTER USER root@localhost IDENTIFIED BY "Lai4451231." ;

修改完毕后刷新特权.

  FLUSH PRIVILEGES;

然后就可以进行修改密码策略了,先查看密码策略.

  SHOW VARIABLES LIKE "%password%";

修改密码策略,修改密码总长度,我这边改成5,为了安全建议8位左右

  SET GLOBAL validate_password_length=5;  

修改密码强度策略,我这边改成低策略就不需要大小写数字和符号了

  SET GLOBAL validate_password_policy=0;

这里是临时生效,要写入到/etc/my.conf里面才能永久生效,查看一下当前修改后的密码策略

  SHOW 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 |
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 5 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+---------------------------------------+-------+
14 rows in set (0.00 sec)

写入到/etc/my.conf中[mysqld]下

validate_password_policy=0
validate_password_length=5

重启服务即可.

systemctl restart mysqld 

 

---恢复内容结束---

posted @ 2019-10-09 14:02  不愿透露姓名的先生  阅读(7707)  评论(0编辑  收藏  举报