| default_password_lifetime | 90 |
+---------------------------+-------+
1 row in set (0.00 sec)
#
创建用户及查看密码有效期及是否过期
MySQL5741> create user 'user1'@'%' identified by 'pwd';flush privileges;
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
MySQL8031> create user 'user1'@'%' identified with mysql_native_password by
'pwd';flush privileges;
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
MySQL> select user,host,password_lifetime,password_expired from mysql.user
where user='user1';
+---------------+-----------+-------------------+------------------+
| user | host | password_lifetime | password_expired |
+---------------+-----------+-------------------+------------------+
| user1 | % | NULL | N |
+---------------+-----------+-------------------+------------------+
1 rows in set (0.00 sec)
当
password_lifetime
为
null
时,代表该用户的密码有效期是使用的全局变量,而
default_password_lifetime
改为
90
,代表用户密码在
90
天后过期。
password_expired
值为
Y/N
,显示该用户密码是否过期。
#
在
90
天内可通过下面脚本更新密码重新开始计算用户密码过期时间
MySQL5741> alter user 'user'@'host' identified by 'newpwd';flush privileges;
MySQL8031> alter user 'user'@'host' identified with mysql_native_password by
'newpwd';flush privileges;
2、自定义密码过期策略
除了定义默认的密码过期策略,也可以为指定账号定义自定义过期策略。
#
设置密码永不过期即
password_lifetime
为
0
MySQL> alter user 'user1'@'%' password expire never;flush privileges;select
user,host,password_lifetime,password_expired from mysql.user where
user='user1';
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
文档被以下合辑收录
评论