MySQL 5.1.41: MySQL 用户密码是否像 Oracle 中一样过期?

MySQL 5.1.41: Does the MySQL User password expire like in Oracle?

我以前从未更改过 root 用户的密码,而且它的密码从未过期。现在我必须更改它的密码,我将使用此代码来完成它:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('StrongPassword');
SET PASSWORD FOR 'root'@'%' = PASSWORD('StrongPassword');

密码很快就会过期吗?如果可以,如何查询有效期?

在Oracle中,我使用

select
     ACCOUNT_STATUS
    ,USERNAME
    ,EXPIRY_DATE
from
    DBA_USERS
;

MySQL 中是否有类似的事情是我应该关注的?

这取决于 MySQL 的版本及其设置方式。来自 MySQL docs:

MySQL enables database administrators to expire account passwords manually, and to establish a policy for automatic password expiration

另外:

Automatic password expiration is available in MySQL 5.7.4 and later. The mysql.user table indicates for each account when its password was last changed, and the server automatically treats the password as expired at client connection time if it is past its permitted lifetime. This works with no explicit manual password expiration.

默认时间为 0,因此永不过期(版本 5.7.4),但 5.7.10 中的默认时间为 360,以天为单位。如果需要,它可以设置为永不过期

您可以检查 default_password_lifetime

的选项文件

如果您想建立全局策略,请将此参数设置为您希望密码过期的天数。

在单用户上你可以运行这个:

ALTER USER 'johndoe'@'localhost' PASSWORD EXPIRE INTERVAL 30 DAY;