标签:多少 简单 修改 log res 默认值 上班 host sys
一、起源:
今天一上班就听到说error-log里记录了大量的
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
二、mysql 用户密码过期的处理:
1、从一条简单的create user 看mysql密码过期的内在逻辑
mysql> create user exuser@‘%‘ identified by ‘exPass@352‘; Query OK, 0 rows affected (0.01 sec) mysql> show create user exuser@‘%‘; +---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | CREATE USER for exuser@% | +---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | CREATE USER ‘exuser‘@‘%‘ IDENTIFIED WITH ‘mysql_native_password‘ AS ‘*CD089516E876A47FEBF3BB6A9ADD45F02F4BF73B‘ REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK | +---------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
2、从上面的show create user 可以看出 mysql会悄悄的在create user 语句的后面加上一个 password expire defautl 子句;这个
password expire default 子句就是用来设置mysql 账号的密码过期时间的(单位天)。
3、看写死mysql 账号密码的过期时间时mysql是怎么处理的
mysql> create user tt@‘%‘ identified by ‘123456‘ password expire interval 30 day; Query OK, 0 rows affected (0.00 sec) mysql> show create user tt@‘%‘; +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | CREATE USER for tt@% | +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | CREATE USER ‘tt‘@‘%‘ IDENTIFIED WITH ‘mysql_native_password‘ AS ‘*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9‘ REQUIRE NONE PASSWORD EXPIRE INTERVAL 30 DAY ACCOUNT UNLOCK | +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4、password expire default 这里的default的值是参照default_password_lifetime这个variable的,也就是说可以通过
改变default_password_lifetime的值来灵活的控制账号的过期时间。
三、default_password_lifetime 地默认值:
目前 default_password_lifetime 这个参数的默认值是0 ,也就是说默认情况下 create user xxx@xxx identified by ‘xxx‘ 这样
创建出来的账号密码是永不过期的。
四、回答一下起源中的问题:
“起源”中提到的密码过期是因为在mysql-5.7.4 ~ mysql-5.7.10 这些版本中default_password_lifetime的默认值是360,
这样就尴尬了,这样的设置使得默认情况下mysql运行个360天就要改一下密码,这不科学!于是呢在mysql-5.7.11 以后
的mysql就把default_password_lifetime这个参数的默认值设置成了0.
五、给你一个环境怎么才看出来用户的密码有没有过期
对于这里所提到的密码过期的判定不能简单的看user.password_expired 这个列来区分账号的密码有没有过期,而是要根据mysql账号过期的
内在逻辑来看
1、第一步:查看user.assword_last_changed 列来看对应账号密码的最近一次的修改时间
mysql> select user,host,password_expired,password_last_changed,password_lifetime from user; +---------------+-----------+------------------+-----------------------+-------------------+ | user | host | password_expired | password_last_changed | password_lifetime | +---------------+-----------+------------------+-----------------------+-------------------+ | root | localhost | N | 2017-10-15 10:07:32 | NULL | | mysql.session | localhost | N | 2017-10-04 12:27:10 | NULL | | mysql.sys | localhost | N | 2017-10-04 12:27:10 | NULL | | jianglexing | localhost | N | 2017-10-07 09:48:14 | NULL | | repl | % | N | 2017-10-07 19:16:44 | NULL | | tstuser | localhost | N | 2017-10-12 10:04:17 | NULL | +---------------+-----------+------------------+-----------------------+-------------------+
2、第二步:查看default_password_lifetime这个变量的值是多少
mysql> show global variables like ‘default_password_lifetime‘; +---------------------------+-------+ | Variable_name | Value | +---------------------------+-------+ | default_password_lifetime | 1 | +---------------------------+-------+ 1 row in set (0.00 sec)
3、确定用户是不是用的mysql全局的密码过期策略
mysql> show create user tstuser@‘localhost‘; +-------------------------------------------------------------------------------------------------------------------------------+ | CREATE USER for tstuser@localhost | +-------------------------------------------------------------------------------------------------------------------------------+ | CREATE USER ‘tstuser‘@‘localhost‘ IDENTIFIED WITH ‘mysql_native_password‘ REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK | +-------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
4、确定当前的时间
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2017-10-15 11:02:36 | +---------------------+ 1 row in set (0.00 sec)
5、结论:
对于tstuser来说它用的是全局的密码过期策略,也就是一天后密码就过期,然而它最近一次更新密码的时间是2017-10-12,而当前的时间已经是
2017-10-15 所以可以确定的说tstuser的密码已经过期了。
标签:多少 简单 修改 log res 默认值 上班 host sys
原文地址:http://www.cnblogs.com/JiangLe/p/7655165.html