MySQL & MariaDB error 1045: Access denied for user (using password)
Access denied for user 'loader'@'localhost' (using password: YES) (5.6.51) The server rejected the login. The user name, password or the host you are connecting from doesn't match any account. "using password: NO" means no password was sent at all.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_ACCESS_DENIED_ERROR | ER_ACCESS_DENIED_ERROR |
| SQLSTATE | 28000 | 28000 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
MySQL accounts are a user name plus a host: 'app'@'localhost' and 'app'@'%' are two different accounts with their own passwords and privileges. At login the server picks the most specific account matching both your user name and the address you connect from, then checks the password against that one account. If nothing matches, or the password is wrong, you get 1045.
The message tells you which account the server tried: Access denied for user 'app'@'10.0.0.5' (using password: YES).
Why it happens
- Wrong password, or a password with special characters that the shell mangled (
-pPa$$wordwithout quotes). - Wrong host: the account exists as
'app'@'localhost'but you connect over TCP from another machine (or through Docker, where the host is the container’s IP), so'app'@'%'or'app'@'10.0.0.%'is needed. using password: NO: the client sent no password, often a missing-por an empty value in the application config.- Socket vs TCP:
-h localhostuses the Unix socket on Linux and matches'user'@'localhost';-h 127.0.0.1uses TCP and matches'user'@'127.0.0.1'or'user'@'%'. - On Ubuntu/Debian MariaDB and MySQL,
rootoften logs in with theunix_socket/auth_socketplugin:sudo mysqlworks, a password login doesn’t (that case is error 1698). - On MySQL 5.6/5.7 a missing FILE privilege for
SELECT … INTO OUTFILEwas also reported as 1045; MySQL 8.0 and MariaDB give the clearer 1227.
How to fix it
- See which accounts exist for that user:
SELECT user, host, plugin FROM mysql.user WHERE user = 'app';(as an admin). - Create or fix the account for the host you really connect from, and reset the password:
CREATE USER 'app'@'%' IDENTIFIED BY '…';orALTER USER 'app'@'%' IDENTIFIED BY '…'; - Quote passwords in the shell (
-p'Pa$$word'), or use-palone and type it at the prompt. - After logging in,
SELECT CURRENT_USER();shows which account the server matched, which is the quickest way to spot a host mismatch. - Locked out of root completely? See the root password reset guide; the right recipe depends on your version.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database:CREATE DATABASE demo; USE demo;In a shell on the database host:
mysql -uroot -pwrong-password -h127.0.0.1 -e 'SELECT 1'
You get: ERROR 1045 (28000): Access denied for user 'root'@'127.0.0.1' (using password: YES)(11.8.9)
Verified fixes
Create the account for the host you connect from, then log in
CREATE USER 'appuser'@'%' IDENTIFIED BY 'Test#1234'; GRANT SELECT ON demo.* TO 'appuser'@'%';mysql -uappuser -p'Test#1234' -h127.0.0.1 -N -e 'SELECT CURRENT_USER()'
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| Log in with the wrong password repro | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 |
| Create the account for the host you connect from, then log in fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Account exists only for 'localhost' but you connect over TCP from another host version check | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 | ✓ 1045 |
Related errors
Where this error shows up in our guides
- LOAD DATA INFILE · LOAD DATA INFILE as a user without FILE privilege (post shows 1045) MySQL 5.6 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
- OUTFILE required permissions · INTO OUTFILE as a user without FILE privilege (1045 on 5.x, clearer 1227 on 8.0+/MariaDB) MySQL 5.6 5.7