MySQL enables database administrators to expire account passwords manually, and to establish a policy for automatic password expiration.
To expire a password manually, the database administratior uses
ALTER USER statement:
ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE;
This operation marks the password expired in the corresponding
mysql.user table row.
Automatic password expiration is available in MySQL 5.7.4 and
mysql.user table indicates for each
account when its password was last changed, and the server
automatically the server treats the password as expired at client
connection time if it is past its permitted lifetime. This works
with no explicit manual password expiration.
system variable defines the global automatic password expiration
policy. It applies to accounts that use MySQL built-in
authentication methods (accounts that use an authentication plugin
The default global policy is that passwords have a lifetime of 360
days. To change the policy, change the value of The
default_password_lifetime. If the
value is a positive integer, it indicates the permitted password
lifetime in days. A value of 0 disables automatic expiration.
To establish a global policy that passwords have a lifetime of approximately six months, start the server with these lines in an option file:
To establish a global policy such that passwords never expire,
SET GLOBAL default_password_lifetime = 180;
No matter the global policy, it can be overridden for individual
Require the password to be changed every 90 days:
ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE INTERVAL 90 DAY;
Disable password expiration:
ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER;
Defer to the global expiration policy:
ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE DEFAULT;
ALTER USER statements update
mysql.user table row.
When a client successfully connects, the server determines whether the account password is expired:
The server checks whether the password has been manually expired and, if so, restricts the session.
Otherwise, the server checks whether the password is past its lifetime according to the automatic password expiration policy. If so, the server considers the password expired and restricts the session.
A restricted session remains that way until the client executes a
SET PASSWORD statement to change
the account password. In restricted mode, operations result in an
error until the user issues a
PASSWORD statement to establish a new account password:
SELECT 1;ERROR 1820 (HY000): You must SET PASSWORD before executing this statement mysql>
SET PASSWORD = PASSWORD('Query OK, 0 rows affected (0.01 sec) mysql>
SELECT 1;+---+ | 1 | +---+ | 1 | +---+ 1 row in set (0.00 sec)
It is also possible for an administrative user to reset the account password, but any existing sessions for the account remain restricted. Clients using the account must disconnect and reconnect before statements can be executed successfully.
It is possible to “reset” a password by setting it to its current value. As a matter of good policy, it is preferable to choose a different password.