原 MySQL数据库密码过期的处理ERROR 1820
现象
1 2 3 4 5 | Your password has expired. To log in you must change it using a client that supports expired passwords. mysql> desc mysql.user; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. |
分析
mysql.user 表中关于密码过期的字段,
password_expired:从 MySQL 5.6.6 版本开始,添加了 password_expired 功能,它允许设置用户的过期时间。
password_last_changed:密码最后一次修改的时间。
password_lifetime:该用户密码的生存时间,默认值为 NULL,除非手动修改此用户密码过期机制,否则都是 NULL。
另外解释一个参数:
default_password_lifetime:从 MySQL 5.7.4 版本开始,此全局变量可以设置一个全局的自动密码过期策略。
解决
1 2 3 4 5 6 7 8 9 10 11 12 13 | SELECT a.`User`,a.host, a.password_expired,a.password_lifetime,a.password_last_changed,a.account_locked from mysql.user a; update mysql.user set password_lifetime=null where password_lifetime is not null; update mysql.user set password_expired='N' where password_expired='Y'; flush privileges; ALTER USER 'root'@'localhost' PASSWORD EXPIRE INTERVAL 30 DAY; ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; ALTER USER 'root'@'%' PASSWORD EXPIRE NEVER; ALTER USER 'testuser'@'localhost' PASSWORD EXPIRE DEFAULT; |