MySQL Error 1045: Access Denied for User (tested)

ERROR 1045 (28000): Access denied for user means the MySQL server rejected the username/password combination itself, before it even looked at what you're trying to do. It's purely an authentication failure. A related but different error, 1044, means the login succeeded but that user isn't authorized for a specific database — section 4 below shows the difference.

1. Reading the error

The full message tells you exactly what MySQL tried and what the client sent:

ERROR 1045 (28000): Access denied for user 'appuser'@'localhost' (using password: YES)

Three useful facts are packed in here: the username MySQL matched against ('appuser'), the host it thinks you're connecting from ('localhost'), and whether a password was sent at all (using password: YES or NO). That last part is the most useful: it tells you whether your client even tried to authenticate, or sent nothing.

2. Four reproduced cases (MySQL 8.4.11)

ScenarioExact error
Correct username, wrong passwordERROR 1045 (28000): Access denied for user 'appuser'@'localhost' (using password: YES)
Correct username, no password supplied at allERROR 1045 (28000): Access denied for user 'appuser'@'localhost' (using password: NO)
Username that doesn't existERROR 1045 (28000): Access denied for user 'nouser'@'localhost' (using password: YES)
root login with no password set up for that hostERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: NO)

Note the third row: MySQL gives the identical error for a wrong password and for a user that doesn't exist at all. This is deliberate — it stops an attacker from using the error message to discover which usernames are valid.

3. The host part matters as much as the username

MySQL grants are scoped to a host pattern, not just a username. 'appuser'@'localhost' and 'appuser'@'127.0.0.1' and 'appuser'@'%' are three separate grants as far as MySQL is concerned, even though they look like the same user. In our fourth test case, root had no grant allowing a password-based login from 127.0.0.1 (only via the local Unix socket), so it failed even with a correct identity and no typo anywhere.

Check what's actually granted:

mysql> SELECT user, host FROM mysql.user WHERE user = 'appuser';
mysql> SHOW GRANTS FOR 'appuser'@'%';

4. 1045 vs 1044: authentication vs authorization

These are commonly confused but different problems. We reproduced both:

-- 1045: the login itself failed (wrong password, bad user, etc.)
ERROR 1045 (28000): Access denied for user 'appuser'@'localhost' (using password: YES)

-- 1044: login succeeded, but this user has no grant on this specific database
ERROR 1044 (42000) at line 1: Access denied for user 'appuser'@'%' to database 'mysql'

If you see 1044, the username and password are fine — the fix is a GRANT, not a password change:

mysql> GRANT SELECT ON mysql.* TO 'appuser'@'%'; FLUSH PRIVILEGES;
-- after the grant, the same query that failed now works:
mysql> USE mysql; SELECT 1;
1

5. Fixing 1045 itself

6. Don't over-fix: avoid blanket solutions

A common but risky "fix" circulating online is granting 'user'@'%' with all privileges to make the error disappear. That papers over whichever specific mismatch (wrong password, wrong host, missing grant) is actually happening, and widens the account's access far beyond what it needs. Diagnose with section 2's table first — the (using password: YES/NO) part alone usually tells you whether this is a credentials problem or a configuration problem.

Frequently asked questions

What does "using password: NO" mean if I know I typed a password?

It means the client didn't send one to the server at all — usually because the password argument was empty, omitted, or (in some tools) read from an empty environment variable or config file rather than what you typed interactively. We reproduced this by running the mysql CLI with a username but no -p flag at all.

Why does MySQL give the same error for a wrong password and an unknown user?

By design, so an attacker probing usernames can't tell which ones exist from the error message alone. We confirmed both produce the identical ERROR 1045 (28000): Access denied text, differing only in the username echoed back.

I entered the right password but still get 1045 — why?

Check the host MySQL thinks you're connecting from (section 3). Grants are per username+host pair; a grant for 'user'@'localhost' won't match a connection from 127.0.0.1 or a different IP, even with the exact right password.

What's the difference between error 1045 and 1044?

1045 means the login itself (username+password+host) failed. 1044 means the login succeeded but that account has no privileges on the specific database you tried to use — we reproduced ERROR 1044 ... Access denied ... to database 'mysql' with correct credentials but a missing GRANT.

Does restarting MySQL fix 1045?

No — in our tests, ALTER USER ... IDENTIFIED BY took effect immediately for the next connection, with no restart needed. If restarting "fixed" it for you, something else (like a config file being reloaded) was the actual cause.

Written with AI assistance. Measured on 2026-10-03 with MySQL 8.4.11 (official Docker image), using the mysql CLI. Every error message below is copy-pasted output, not paraphrased. PlainHeaders is our extension; MySQL and Docker are free.