How to Fix MySQL Error 1820 (ER_MUST_CHANGE_PASSWORD)
You see mysql error 1820 when your database user account has an expired password. To fix this error, you must reset the account password before running any queries. MySQL logs this failure under the symbol ER_MUST_CHANGE_PASSWORD and SQLSTATE HY000. The server returns a strict message when this happens. It states that you must reset your password using an alter user statement first. Until you complete this step, the database blocks all normal operations for that session. Why mysql error 1820
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You see mysql error 1820 when your database user account has an expired password. To fix this error, you must reset the account password before running any queries.
MySQL logs this failure under the symbol ER_MUST_CHANGE_PASSWORD and SQLSTATE HY000. The server returns a strict message when this happens. It states that you must reset your password using an alter user statement first. Until you complete this step, the database blocks all normal operations for that session.
Why mysql error 1820 happens in your database
Database admins use password expiration rules to keep accounts safe. When an account hits its time limit, the server marks the secret as expired. The user can still log in to the database server. Still, the server places that session into a restricted sandbox mode right away.
In this sandbox mode, the client cannot read tables or write new data. Any attempt to run normal queries triggers mysql error 1820 right away. This often happens after a fresh database install as well. Many installers create a temporary root secret that expires on first login.
Automated password policies also trigger this state across production clusters. If a global timer runs out, service accounts can enter this restricted mode overnight. Admins can also force a manual expire on a user account during security incidents.
How to diagnose and fix expired credentials in production
To find the affected account, check your app error logs for SQLSTATE HY000. Look for the exact user account name that failed the query check. Next, have an admin log in with a working account to inspect user states. The admin can check the system user table to see which accounts show expired status.
Fixing the issue for a human user is simple. The user logs in and runs a statement to alter their own user secret. Once they set a new secret, the server lifts the sandbox limit at once. The user does not even need to log out and log back in.
Application-to-Application Password Management + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Service accounts for backend apps require extra care during a fix. If you change a service secret directly, running apps will fail to log in. First, prepare your secret store or app settings to accept the new secret. Next, update the user secret in the database using an alter user statement. Finally, update the app settings and restart the workers so they use the new secret.
How to prevent sudden password lockouts
Never disable security checks across the whole server just to avoid this error. Turning off expiration rules leaves human accounts open to old credential leaks. Instead, split your database accounts into two clear groups for humans and apps.
Keep strict expiration timers on all human user accounts. People can easily type a new secret when their SQL client shows the error prompt. For backend apps, use dedicated roles with planned secret rotation schedules. Rotate those app secrets on a fixed calendar before the database timer runs out. You should also mask sensitive data like emails and card numbers in query results. Masking rewrites matched fields in results so expired or compromised accounts expose less data.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
What does SQLSTATE HY000 with error 1820 mean?
It means your login worked, but your password is expired. The server puts your session in a sandbox until you set a new password.
Why can my app log in if the password is expired?
MySQL allows the initial login so the user has a way to change their password. The server blocks all other commands during that session.
How do I stop mysql error 1820 from breaking automated scripts?
Rotate your script passwords on a planned schedule before the database timer expires. You can also use short-lived access tokens instead of static passwords.
Related guides
In this post