作者:Sri Sakthivel
原文链接:https://www.percona.com/blog/enhanced-password-management-systems-in-mysql-8-part-1
MySQL 8.0 在密码管理方面有很多改善,本文将介绍以下两个特性。
- 密码重用策略
- 生成随机密码
| 1 密码重用策略
该策略简单说,就是设置新密码时,可以限制禁止使用曾经用过的密码。有以下两种策略:
- 历史密码 password_history
- 间隔时间 password_reuse_interval
1.1 历史密码
MySQL 官方手册描述:
If an account is restricted on the basis of number of password changes, a new password cannot be chosen from a specified number of the most recent passwords.
在实验环境中,创建用户并添加条件password history 2
,历史密码中最近的两个不能被重新使用。
mysql> create user 'herc'@'localhost' identified by 'Percona@321' password history 2;
Query OK, 0 rows affected (0.02 sec)
mysql> select user, host, password_reuse_history from mysql.user where user='herc'\G
*************************** 1. row ***************************
user: herc
host: localhost
password_reuse_history: 2
1 row in set (0.00 sec)
MySQL 将在 mysql.password_history
表上记录密码更改的信息。
mysql> select * from mysql.password_history;
+-----------+------+----------------------------+------------------------------------------------------------------------+
| Host | User | Password_timestamp | Password |
+-----------+------+----------------------------+------------------------------------------------------------------------+
| localhost | herc | 2021-09-20 15:44:42.295778 | $A$005$=R:q'M(K