mysqldude
Error codes › 1045

MySQL & MariaDB error 1045: Access denied for user (using password)

Error messageAccess denied for user '…'@'…' (using password: …)
Example from our test runs: 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.

MySQLMariaDB
SymbolER_ACCESS_DENIED_ERRORER_ACCESS_DENIED_ERROR
SQLSTATE2800028000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery 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$$word without 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 -p or an empty value in the application config.
  • Socket vs TCP: -h localhost uses the Unix socket on Linux and matches 'user'@'localhost'; -h 127.0.0.1 uses TCP and matches 'user'@'127.0.0.1' or 'user'@'%'.
  • On Ubuntu/Debian MariaDB and MySQL, root often logs in with the unix_socket/auth_socket plugin: sudo mysql works, a password login doesn’t (that case is error 1698).
  • On MySQL 5.6/5.7 a missing FILE privilege for SELECT … INTO OUTFILE was also reported as 1045; MySQL 8.0 and MariaDB give the clearer 1227.

How to fix it

  1. See which accounts exist for that user: SELECT user, host, plugin FROM mysql.user WHERE user = 'app'; (as an admin).
  2. Create or fix the account for the host you really connect from, and reset the password: CREATE USER 'app'@'%' IDENTIFIED BY '…'; or ALTER USER 'app'@'%' IDENTIFIED BY '…';
  3. Quote passwords in the shell (-p'Pa$$word'), or use -p alone and type it at the prompt.
  4. After logging in, SELECT CURRENT_USER(); shows which account the server matched, which is the quickest way to spot a host mismatch.
  5. 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.

  1. Connect with mysql -u root -p and create a scratch database:

    CREATE DATABASE demo;
    USE demo;
  2. 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

  1. 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

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.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
Log in with the wrong password repro
MySQL 5.6✓ 10455.7✓ 10458.0✓ 10458.4✓ 10459✓ 1045
MariaDB 10.6✓ 104510.11✓ 104511.4✓ 104511.8✓ 1045
Create the account for the host you connect from, then log in fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
Account exists only for 'localhost' but you connect over TCP from another host version check
MySQL 5.6✓ 10455.7✓ 10458.0✓ 10458.4✓ 10459✓ 1045
MariaDB 10.6✓ 104510.11✓ 104511.4✓ 104511.8✓ 1045
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

Related errors

  • 1044 ER_DBACCESS_DENIED_ERRORexplained
  • 1698 ER_ACCESS_DENIED_NO_PASSWORD_ERRORexplained
  • 1130 ER_HOST_NOT_PRIVILEGEDexplained
  • 2059 CR_AUTH_PLUGIN_CANNOT_LOAD

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