MySQL 8.4Lab-verified · 2026-11-30

MySQL ERROR 3118 (HY000): Access denied for user 'app_user'@'127.0.0.1'. Account is locked.

The account exists, but it is marked as locked, so MySQL refuses the login even with the right password.

MySQL 8.4.13
3118 (HY000): Access denied for user 'app_user'@'127.0.0.1'. Account is locked.

Jump to a cause

  1. 01The account was locked with ACCOUNT LOCK
  2. 02Logged in with a role name instead of a user

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-30 · container image mysql:8.4

ERROR 3118 is a login refusal for a locked account. Unlike ERROR 1045, the user and password are not the problem; mysql.user.account_locked is Y for the matched account.

Check it as an admin with SELECT user, host, account_locked FROM mysql.user WHERE user = '...';. Below are the two cases we reproduced by logging in with the mysql client.

01The account was locked with ACCOUNT LOCK

app_user was created normally and then locked with ALTER USER 'app_user'@'%' ACCOUNT LOCK. Logging in with the correct password returned Account is locked.

mysql.user showed account_locked = Y. After ALTER USER 'app_user'@'%' ACCOUNT UNLOCK it became N, and the same login worked (CURRENT_USER() = app_user@%). If someone locked the account on purpose (a retired user, for example), ask before unlocking.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE USER 'app_user'@'%' IDENTIFIED BY 'App_Pw_2026';
GRANT ALL ON shop.* TO 'app_user'@'%';
ALTER USER 'app_user'@'%' ACCOUNT LOCK;
OUTPUT
Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)
Reproducerun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'App_Pw_2026' shop
SELECT CURRENT_USER();
✕ ERROR
ERROR 3118 (HY000): Access denied for user 'app_user'@'127.0.0.1'. Account is locked.
Checkrun as root
SELECT user, host, account_locked FROM mysql.user WHERE user = 'app_user';
OUTPUT
+----------+------+----------------+
| user     | host | account_locked |
+----------+------+----------------+
| app_user | %    | Y              |
+----------+------+----------------+
1 row in set (0.00 sec)
Fixrun as root
ALTER USER 'app_user'@'%' ACCOUNT UNLOCK;
SELECT user, host, account_locked FROM mysql.user WHERE user = 'app_user';
OUTPUT
Query OK, 0 rows affected (0.01 sec)

+----------+------+----------------+
| user     | host | account_locked |
+----------+------+----------------+
| app_user | %    | N              |
+----------+------+----------------+
1 row in set (0.00 sec)
After the fixrun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'App_Pw_2026' shop
SELECT CURRENT_USER();
✓ SUCCESS
+----------------+
| CURRENT_USER() |
+----------------+
| app_user@%     |
+----------------+
1 row in set (0.00 sec)

02Logged in with a role name instead of a user

report_role was created with CREATE ROLE and given SELECT ON shop.*. Logging in as report_role returned ERROR 3118. In MySQL a role is stored in mysql.user as a locked account with no password, so it can never log in.

The check showed account_locked = Y and no password. The fix was a real user: CREATE USER 'report_user'@'%', GRANT report_role TO ... and SET DEFAULT ROLE report_role TO .... Logging in as report_user, CURRENT_ROLE() returned report_role@% and SELECT * FROM orders returned the row.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE TABLE shop.orders (id INT PRIMARY KEY, amount INT);
INSERT INTO shop.orders VALUES (1, 100);
CREATE ROLE report_role;
GRANT SELECT ON shop.* TO report_role;
OUTPUT
Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)
Reproducerun as report_role
$ mysql -h 127.0.0.1 -u report_role shop
SELECT * FROM orders;
✕ ERROR
ERROR 3118 (HY000): Access denied for user 'report_role'@'127.0.0.1'. Account is locked.
Checkrun as root
SELECT user, host, account_locked, authentication_string = '' AS no_password FROM mysql.user WHERE user = 'report_role';
OUTPUT
+-------------+------+----------------+-------------+
| user        | host | account_locked | no_password |
+-------------+------+----------------+-------------+
| report_role | %    | Y              |           1 |
+-------------+------+----------------+-------------+
1 row in set (0.00 sec)
Fixrun as root
CREATE USER 'report_user'@'%' IDENTIFIED BY 'Report_Pw_2026';
GRANT report_role TO 'report_user'@'%';
SET DEFAULT ROLE report_role TO 'report_user'@'%';
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Without SET DEFAULT ROLE, a granted role is not active after login; you would need SET ROLE report_role; in each session.

After the fixrun as report_user
$ mysql -h 127.0.0.1 -u report_user -p'Report_Pw_2026' shop
SELECT CURRENT_ROLE();
SELECT * FROM orders;
✓ SUCCESS
+-------------------+
| CURRENT_ROLE()    |
+-------------------+
| `report_role`@`%` |
+-------------------+
1 row in set (0.00 sec)

+----+--------+
| id | amount |
+----+--------+
|  1 |    100 |
+----+--------+
1 row in set (0.00 sec)

FAQ

How do I unlock a MySQL account?

As an admin: ALTER USER 'user'@'host' ACCOUNT UNLOCK;. In our run account_locked changed from Y to N and the login worked right away.

How do I see which accounts are locked?

SELECT user, host, account_locked FROM mysql.user WHERE account_locked = 'Y';. Roles created with CREATE ROLE also appear here as locked.

Can I log in with a role created by CREATE ROLE?

No. A role is a locked account without a password, so logging in with its name gives ERROR 3118. Create a user, grant the role to it, and set it as the default role.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13