Common SQL Errors

MySQL Error 1820: ER_MUST_CHANGE_PASSWORD - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>MySQL raises Error 1820 when an account is forced to change its password before any statement can run.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1820?

<p>MySQL Error 1820 ER_MUST_CHANGE_PASSWORD signals that the current account must reset its password before executing queries. Connect as the user or an administrator and run ALTER USER IDENTIFIED BY 'NewStrongPass!'; to clear the expired flag and restore access.</p>

Error Highlights

Typical Error Message

You must reset your password using ALTER USER statement

Error Type

Authentication Error

Language

MySQL

Symbol

ER_MUST_CHANGE_PASSWORD

Error Code

1820

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1820 ER_MUST_CHANGE_PASSWORD?

MySQL throws Error 1820 with the condition name ER_MUST_CHANGE_PASSWORD when an account is flagged to change its password before executing any statement.

This security safeguard appears immediately after a DBA creates a user with the PASSWORD EXPIRE option or when a scheduled password expiration policy triggers.

When does Error 1820 occur?

The error surfaces during the first login attempt or any subsequent query executed by the affected account until the password is reset.

Applications that reuse pooled connections will also fail until the password change is completed.

Why is it important to fix Error 1820 quickly?

Leaving the account in an expired state blocks all data access, interrupts services, and can hide deeper authentication policy issues.

Promptly resetting the password restores availability and keeps you compliant with security rules.

What Causes This Error?

The immediate cause is the ACCOUNT has_password_expired flag set to Y in mysql.user.

This flag can be set by password expiration policies, manual DBA action, or MySQL upgrade scripts that detect weak defaults.

How to Fix MySQL Error 1820

Login as the affected user or a privileged administrator and run ALTER USER user IDENTIFIED BY 'NewStrongP@ss1';

This statement resets the password, clears the expired flag, and allows the session to proceed normally.

Common Scenarios and Solutions

If the application uses a service account, deploy an automated script that updates the credential in both MySQL and your secrets manager.

For multiple expired accounts, loop through mysql.user where account_locked = 'N' and password_expired = 'Y' and alter each user inside a transaction.

Best Practices to Avoid This Error

Set a rotation policy that notifies owners before expiration, and use MySQL 8 PASSWORD EXPIRE INTERVAL to stagger resets.

Store all credentials in Galaxy Secrets so developers can update them centrally without code changes.

Related Errors and Solutions

Error 1862 ER_PASSWORD_EXPIRE_ANONYMOUS_USER occurs when an anonymous user must change a password; fix it with the same ALTER USER command.

Error 1822 ER_PASSWORD_EXPIRE_RESERVED_NAME appears when a reserved account hits expiration; rebuild the account with a stronger password.

Common Causes

Password created with EXPIRE option

The DBA might have run CREATE USER ... PASSWORD EXPIRE which forces an immediate password change.

System wide password expiration policy

MySQL variable default_password_lifetime forces accounts to expire after N days, triggering Error 1820.

Account imported during upgrade

When migrating from older versions, MySQL flags accounts that used obsolete hashing methods as expired.

Manual flag in mysql.user

Someone may have updated the mysql.user table and set password_expired to Y.

Related Errors

MySQL Error 1862 ER_PASSWORD_EXPIRE_ANONYMOUS_USER

Raised when the anonymous account must change its password. Reset or drop the anonymous user.

MySQL Error 1822 ER_PASSWORD_EXPIRE_RESERVED_NAME

Occurs when a reserved account like mysql.sys is expired. Use ALTER USER or skip name remapping.

MySQL Error 1045 Access denied for user

General authentication failure, often seen after error 1820 if the password was changed incorrectly.

MySQL Error 3159 PASSWORD EXPIRE GRACE PERIOD

Indicates the user is in grace period before forced expiration; change the password to avoid hitting error 1820.

FAQs

Do I need SUPER privilege to run ALTER USER?

No. In MySQL 8 the ALTER USER privilege is sufficient, which is granted automatically to accounts that can change their own password.

Can I disable password expiration globally?

Yes. Set default_password_lifetime = 0 in my.cnf and restart, but evaluate security compliance before disabling.

How do I know which accounts are expired?

Query mysql.user where password_expired = 'Y'. Monitor this in Galaxy with a saved query.

Will changing the password break replication?

If the replication user is expired, update its credential in both master and replica configuration files after running ALTER USER.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo