MySQL user passwords and password expiration

MySQL account passwords are administrative credentials for connecting to the server. They are separate from passwords your application stores for its own users. For MySQL accounts, ALTER USER is the preferred current statement for changing authentication settings.

MySQL password expired connection error

Change a MySQL account password

ALTER USER 'usrname'@'localhost'
IDENTIFIED BY 'new-strong-password';

Avoid placing real administrative passwords in tutorial source, version control, URLs or command history.

Change the authenticated current account

ALTER USER CURRENT_USER()
IDENTIFIED BY 'new-strong-password';

Require a password change

ALTER USER 'user_id'@'localhost'
PASSWORD EXPIRE;

Disable expiration for one account

ALTER USER 'my_userid'@'localhost'
PASSWORD EXPIRE NEVER;

Set an account-specific expiration interval

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

Set the server default password lifetime

SET GLOBAL default_password_lifetime = 60;

A value of 0 disables automatic expiration through the global default:

SET GLOBAL default_password_lifetime = 0;
Changing server-wide password policy normally requires administrative privileges. On managed hosting, cloud databases and shared hosting, use the provider's supported account-management workflow.

For application-user passwords, use PHP's password-hashing APIs rather than MySQL account-management statements. For database connection examples, see PDO/MySQLi connection.

Database connections · Error handling · PHP/MySQL overview · MySQL installation · Database administration

← All PHP & MySQL topics




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer