当 MySQL 密码过期时,可以通过以下步骤解决:
mysql -u root -p 输入 root 用户密码,进入 MySQL 命令行。
切换到 mysql 数据库:
use mysql; SELECT user, password_expired FROM user; ALTER USER 'username'@'localhost' IDENTIFIED BY 'new_password'; 将 'username' 替换为实际的用户名,'new_password' 替换为想要设置的新密码。
UPDATE user SET password_expired='N' WHERE user='username'; 将 'username' 替换为实际的用户名。
FLUSH PRIVILEGES; exit; 这样,用户的密码就不再过期,并且可以使用新密码登录 MySQL。