Common SQL Errors

MySQL Error 3118 ER_ACCOUNT_HAS_BEEN_LOCKED: Account Locked - How to Fix and Prevent

Galaxy Team
August 8, 2025

MySQL denies the login because the user account is explicitly marked ACCOUNT LOCK, blocking all connections until an administrator unlocks it.

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 3118 ER_ACCOUNT_HAS_BEEN_LOCKED?

MySQL error 3118 ER_ACCOUNT_HAS_BEEN_LOCKED means the login failed because the account is locked. Connect as an administrator and run ALTER USER 'user'@'host' ACCOUNT UNLOCK to restore access.

Error Highlights

Typical Error Message

ER_ACCOUNT_HAS_BEEN_LOCKED

Error Type

Authentication Error

Language

MySQL

Symbol

The account was locked with CREATE USER ... ACCOUNT LOCK or ALTER USER ... ACCOUNT LOCK. An administrator can unlock it with ALTER USER ... ACCOUNT UNLOCK. ER_ACCOUNT_HAS_BEEN_LOCKED was added in 5.7.6.

Error Code

3118

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 3118 (ER_ACCOUNT_HAS_BEEN_LOCKED)?

MySQL raises Error 3118 when a client tries to authenticate with an account whose ACCOUNT LOCK attribute is active. The server instantly returns Access denied for user ... Account is locked, preventing any session creation.

The condition was introduced in MySQL 5.7.6 to give administrators a simple switch for disabling credentials without deleting them.

What Causes This Error?

The primary cause is a manual CREATE USER ... ACCOUNT LOCK or ALTER USER ... ACCOUNT LOCK statement that sets the locked flag in mysql.user.

Security automation, migration scripts, or external IAM hooks may also run ALTER USER automatically after failed-login thresholds, leaving accounts unintentionally locked.

Clone or dump workflows sometimes lock all users in downstream environments to stop accidental production writes, triggering the error until unlocked.

How to Fix ER_ACCOUNT_HAS_BEEN_LOCKED

Connect as a privileged administrator (root or a user with CREATE USER privilege) and run ALTER USER 'account'@'host' ACCOUNT UNLOCK. This instantly clears the flag and allows logins.

If the lock was applied for security, rotate the password with ALTER USER 'account'@'host' IDENTIFIED BY 'NewStrongPwd' ACCOUNT UNLOCK to resume safely.

Common Scenarios and Solutions

Staging databases copied from production ship with every account locked; unlock only required service users and leave human accounts disabled.

During incident response, teams lock compromised accounts; once risk subsides, unlock the account and mandate a password change.

CI/CD pipelines may forget to UNLOCK after resetting passwords; add an explicit ACCOUNT UNLOCK step in deployment scripts.

Best Practices to Avoid This Error

Track ALTER USER statements in version control or Galaxy audit logs to catch unintended locks before deployment.

Use roles and dynamic privileges so you can disable access by revoking role activation instead of fully locking the account.

Periodically review mysql.user for stale locked accounts and drop unused users rather than leaving them permanently disabled.

Related Errors and Solutions

Error 1045 (ER_ACCESS_DENIED_ERROR) indicates wrong credentials rather than a locked account; verify password or host specification.

Error 3159 (ER_ACCOUNT_HAS_BEEN_SUSPENDED) appears when accounts are suspended by the Resource Group feature; UNSUSPEND restores access.

Error 1396 (ER_CANNOT_USER) shows permission problems when altering a user; ensure you have appropriate privileges.

Common Causes

Manual ACCOUNT LOCK

An administrator intentionally disabled the user with ALTER USER ... ACCOUNT LOCK.

Security Automation

Scripts detected suspicious activity and auto-locked the account.

Environment Cloning

Cloned databases keep users but lock them to avoid cross-environment interference.

Related Errors

Error 1045 ER_ACCESS_DENIED_ERROR

Login fails due to bad password or host mismatch.

Error 3159 ER_ACCOUNT_HAS_BEEN_SUSPENDED

Account suspended by Resource Group limits; use UNSUSPEND to reactivate.

Error 1396 ER_CANNOT_USER

Attempt to create or alter user failed because of missing privileges or duplicate entry.

FAQs

Does unlocking a MySQL account require a server restart?

No. ALTER USER ... ACCOUNT UNLOCK takes effect immediately without downtime.

Can I unlock an account without root?

You need CREATE USER or UPDATE privilege on the mysql system database; most production setups grant this only to administrative roles.

Will unlocking reset the failed login counter?

MySQL Community Edition does not track failed counts natively, so there is no counter to reset.

How does Galaxy help?

Galaxy logs and versions every ALTER USER statement, making it easy to audit who locked or unlocked an account and to roll back accidental changes.

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