MySQL 8.4Lab-verified · 2026-12-01

MySQL ERROR 1045 (28000): Access denied for user 'app_user'@'127.0.0.1' (using password: YES)

The server rejected the login: no account matched this user, host and password combination.

MySQL 8.4.13
1045 (28000): Access denied for user 'app_user'@'127.0.0.1' (using password: YES)

Jump to a cause

  1. 01Wrong password (case differs)
  2. 02No password sent (using password: NO)
  3. 03Account exists only for another host (e.g. localhost)
  4. 04Password changed, but an old account for the same user on another host remains
  5. 05An anonymous user ''@'127.0.0.1' takes the login

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-12-01 · container image mysql:8.4

ERROR 1045 is a login failure. The connection never gets as far as a database, so nothing you run afterwards matters until the user, the client host and the password all match one account in mysql.user.

Read the message closely. 'app_user'@'127.0.0.1' is the user and the host the server saw you coming from, and using password: YES/NO tells you whether the client sent a password at all. Below are the five causes we reproduced, each logged in with the mysql client exactly as shown.

01Wrong password (case differs)

The account was created with App_Pw_2026, and the client sent app_pw_2026. MySQL passwords are case-sensitive, so the login failed with Access denied for user 'app_user'@'127.0.0.1' (using password: YES). YES only means a password was sent, not that it was right.

The account itself was fine: mysql.user showed app_user with host % and caching_sha2_password. Logging in again with the exact password worked and CURRENT_USER() returned app_user@%.

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

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)
Reproducerun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'app_pw_2026' shop
SELECT CURRENT_USER();
✕ ERROR
ERROR 1045 (28000): Access denied for user 'app_user'@'127.0.0.1' (using password: YES)
Checkrun as root
SELECT user, host, plugin FROM mysql.user WHERE user = 'app_user';
OUTPUT
+----------+------+-----------------------+
| user     | host | plugin                |
+----------+------+-----------------------+
| app_user | %    | caching_sha2_password |
+----------+------+-----------------------+
1 row in set (0.01 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)

02No password sent (using password: NO)

The same account has a password, but the client connected without -p, so the message ends in using password: NO. This is common when an environment variable or config file that should hold the password is empty.

mysql.user showed the account does have a password (empty_password = 0). Passing the password made the login succeed.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE USER 'app_user'@'%' IDENTIFIED BY 'App_Pw_2026';
GRANT ALL ON shop.* TO 'app_user'@'%';
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)
Reproducerun as app_user
$ mysql -h 127.0.0.1 -u app_user shop
SELECT CURRENT_USER();
✕ ERROR
ERROR 1045 (28000): Access denied for user 'app_user'@'127.0.0.1' (using password: NO)
Checkrun as root
SELECT user, host, plugin, authentication_string = '' AS empty_password FROM mysql.user WHERE user = 'app_user';
OUTPUT
+----------+------+-----------------------+----------------+
| user     | host | plugin                | empty_password |
+----------+------+-----------------------+----------------+
| app_user | %    | caching_sha2_password |              0 |
+----------+------+-----------------------+----------------+
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)

03Account exists only for another host (e.g. localhost)

The account was created as 'app_user'@'localhost', but the client connected over TCP to 127.0.0.1. The server saw the host as 127.0.0.1, no account matched app_user from that host, and the password was correct yet the login still failed with 1045. An app server connecting from another machine hits the same thing with its own IP in the message.

SELECT user, host FROM mysql.user showed only localhost. After creating 'app_user'@'%' and granting shop.*, the login worked: USER() was app_user@127.0.0.1 and CURRENT_USER() was app_user@%, meaning the % account was the one matched.

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

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected, 1 warning (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 1045 (28000): Access denied for user 'app_user'@'127.0.0.1' (using password: YES)
Checkrun as root
SELECT user, host FROM mysql.user WHERE user = 'app_user';
OUTPUT
+----------+-----------+
| user     | host      |
+----------+-----------+
| app_user | localhost |
+----------+-----------+
1 row in set (0.00 sec)
Fixrun as root
CREATE USER 'app_user'@'%' IDENTIFIED BY 'App_Pw_2026';
GRANT ALL ON shop.* TO 'app_user'@'%';
SHOW GRANTS FOR 'app_user'@'%';
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

+----------------------------------------------------+
| Grants for app_user@%                              |
+----------------------------------------------------+
| GRANT USAGE ON *.* TO `app_user`@`%`               |
| GRANT ALL PRIVILEGES ON `shop`.* TO `app_user`@`%` |
+----------------------------------------------------+
2 rows in set (0.00 sec)

% allows any host. In production, prefer the app server's address or subnet (e.g. 'app_user'@'10.0.0.%').

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

04Password changed, but an old account for the same user on another host remains

Only 'app_user'@'%' got the new password New_Pw_2026. An older 'app_user'@'127.0.0.1' account still had the old password. When the user name is the same, MySQL picks the account with the more specific host first, so a connection from 127.0.0.1 was checked against the 127.0.0.1 account and the new password was rejected with 1045.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE USER 'app_user'@'%' IDENTIFIED BY 'Old_Pw_2025';
CREATE USER 'app_user'@'127.0.0.1' IDENTIFIED BY 'Old_Pw_2025';
GRANT ALL ON shop.* TO 'app_user'@'%';
GRANT ALL ON shop.* TO 'app_user'@'127.0.0.1';
ALTER USER 'app_user'@'%' IDENTIFIED BY 'New_Pw_2026';
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.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'New_Pw_2026' shop
SELECT USER(), CURRENT_USER();
✕ ERROR
ERROR 1045 (28000): Access denied for user 'app_user'@'127.0.0.1' (using password: YES)
Check the causerun as root
SELECT user, host FROM mysql.user WHERE user = 'app_user' ORDER BY host;
OUTPUT
+----------+-----------+
| user     | host      |
+----------+-----------+
| app_user | %         |
| app_user | 127.0.0.1 |
+----------+-----------+
2 rows in set (0.00 sec)

mysql.user shows app_user twice, with host % and 127.0.0.1. The exact 127.0.0.1 row wins for connections from that address.

Fixrun as root
DROP USER 'app_user'@'127.0.0.1';
OUTPUT
Query OK, 0 rows affected (0.01 sec)

After dropping the leftover 'app_user'@'127.0.0.1', the login worked and CURRENT_USER() became app_user@%. If you need to keep that account, change its password too.

After the fixrun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'New_Pw_2026' shop
SELECT USER(), CURRENT_USER();
✓ SUCCESS
+--------------------+----------------+
| USER()             | CURRENT_USER() |
+--------------------+----------------+
| app_user@127.0.0.1 | app_user@%     |
+--------------------+----------------+
1 row in set (0.00 sec)

05An anonymous user ''@'127.0.0.1' takes the login

'app_user'@'%' existed and the password App_Pw_2026 was correct, but there was also an anonymous account ''@'127.0.0.1' (empty user name). MySQL sorts accounts by host first, so the more specific 127.0.0.1 row was picked before app_user@%, even though its user name is blank. That account has no password, so the login with a password was rejected with 1045.

Setup
Setuprun as root
CREATE DATABASE shop;
CREATE USER 'app_user'@'%' IDENTIFIED BY 'App_Pw_2026';
GRANT ALL ON shop.* TO 'app_user'@'%';
CREATE USER ''@'127.0.0.1';
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 USER(), CURRENT_USER();
✕ ERROR
ERROR 1045 (28000): Access denied for user 'app_user'@'127.0.0.1' (using password: YES)
Check the causerun as root
SELECT CONCAT('[', user, ']') AS user, host, authentication_string = '' AS empty_password FROM mysql.user WHERE user IN ('app_user', '') ORDER BY host;
OUTPUT
+------------+-----------+----------------+
| user       | host      | empty_password |
+------------+-----------+----------------+
| [app_user] | %         |              0 |
| []         | 127.0.0.1 |              1 |
+------------+-----------+----------------+
2 rows in set (0.00 sec)

Listing mysql.user shows [app_user] on % and [] (an empty user name) on 127.0.0.1 with empty_password = 1. The brackets make the blank name visible.

Fixrun as root
DROP USER ''@'127.0.0.1';
OUTPUT
Query OK, 0 rows affected (0.00 sec)

After DROP USER ''@'127.0.0.1'; the same login worked and CURRENT_USER() was app_user@%.

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

FAQ

What does (using password: YES) mean in ERROR 1045?

Only that the client sent a password. It does not mean the password was right. With a wrong password you still see YES; with no password at all you see NO.

The password is correct but I still get Access denied. Why?

Check the host part. MySQL matches user and host together. In our run 'app_user'@'localhost' existed with the right password, but the login came from 127.0.0.1 and was denied. Run SELECT user, host FROM mysql.user WHERE user = '...'; as an admin.

How do I see which account I actually logged in as?

SELECT USER(), CURRENT_USER();. USER() is what you sent (user@client host), CURRENT_USER() is the account that matched, e.g. app_user@127.0.0.1 vs app_user@%.

What is the difference between ERROR 1045 and ERROR 1044?

1045 means the user/host/password did not match any account. 1044 means they matched, but the account has no privilege on the database it asked for (also at connect time, e.g. a wrong database name in the connection settings).

I changed the MySQL password but still get Access denied. Why?

Check whether the same user exists for several hosts. If SELECT user, host FROM mysql.user WHERE user = '...'; returns both % and 127.0.0.1, the more specific host account is used first. In the run above, the 127.0.0.1 account still had the old password.

MySQL Access denied even with the right password — could it be an anonymous user?

Yes. Run SELECT CONCAT('[', user, ']'), host FROM mysql.user; as an admin. A row with [] and a host more specific than yours (for example 127.0.0.1 vs %) is matched first. In the run above, dropping ''@'127.0.0.1' fixed the login.

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