Mysql password expired. Can't connect

Mysql password expired. Can't connect

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

MySQL Password Expired: Resetting Without a Working Connection

Encountering ERROR 1820 after wiping a system and reinstalling macOS is a classic post-migration headache. You successfully authenticate into the MySQL client using your existing credentials, but the moment you attempt to run a command—whether it's checking version info or creating a new database—the server halts execution with the message: "You must reset your password using ALTER USER statement."

This behavior isn't a bug; it is an intentional security feature designed to force a password rotation when authentication policies are violated. In your specific case, this likely stems from a default policy where MySQL accounts expire after a certain period of inactivity or upon the first login following a major system upgrade. Since you cannot connect via PHP or other applications until the password is reset, you must use the command-line client with the current credentials to perform the administrative fix.

Once inside the MySQL prompt, you need to execute an ALTER USER statement that satisfies the policy requirements. The core logic here is that you are explicitly telling the server to set a new expiration date (or remove one) for the specific user account. Here is the standard procedure:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_secure_password';

However, simply changing the password might not be enough if the policy explicitly requires an immediate expiration check. You may need to clear the expired status flag entirely. In modern MySQL versions (5.7+ and 8.0), you can combine the password change with a policy reset by ensuring the user is not flagged as expired. A more robust approach involves setting the account's expiration attribute to 'never':

ALTER USER 'root'@'localhost' 
IDENTIFIED BY 'your_new_secure_password'
ATTRIBUTE EXPIRE_PASSWORD = 'NEVER';
FLUSH PRIVILEGES;

After running this command, try executing a simple query like SELECT VERSION() or exit the client. If the error persists, check your MySQL configuration file (my.cnf on Linux or my.ini on Windows) for an default_password_lifetime setting. If that value is set to a number greater than 0, MySQL enforces expiration. Setting it to 0 effectively disables automatic expiration:

[mysqld]
default_password_lifetime = 0

Restart the MySQL service after modifying the configuration file. This ensures your new session inherits the relaxed policy immediately.

It is worth noting that this error only appears for users affected by the policy. If you have multiple accounts, you should apply the reset to each one individually or configure a global policy if you manage a production environment. For instance, in a shared hosting setup, forcing a global expiration reset could lock out legitimate users who haven't changed their passwords yet. Always test these changes on a development instance first.

If you are building your application stack with Laravel and want to avoid future headaches, ensure your .env file has the correct credentials. While this specific error is less common in managed cloud databases like AWS RDS or Heroku Postgres without custom policies, it remains relevant for self-hosted instances where you control the my.cnf settings.

For more details on managing MySQL user security policies and password expiration strategies, you can refer to resources like https://laravelcompany.com, which often covers database configuration best practices for modern PHP stacks.

Our network