MySQL

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

ERROR 1045 (28000): Access denied for user — the host/user/password mismatch behind it, and the exact steps to fix or reset it.

What it means

ERROR 1045 (28000): Access denied for user (ER_ACCESS_DENIED_ERROR, SQLSTATE 28000) means the MySQL server received your connection and rejected the specific user@host account and password combination you offered. This is different from a connection failure — the client and server already talked to each other; the server is telling you the credentials it received don’t match an account it will authenticate.

Common causes

  • Wrong password, including one that changed after a script or password manager cached the old one.
  • Connecting from a host the account isn’t allowed to use. MySQL treats 'user'@'host' as a single account identity — a password that works for 'app'@'localhost' will still be rejected for a connection arriving as 'app'@'10.0.0.5' unless that account (or a matching 'app'@'%') also exists with the same password.
  • The account genuinely doesn’t exist, or was created without the privileges/host pattern you assume.
  • Case or quoting differences in scripts — MySQL user names are case-sensitive (host names are not), and an unescaped special character in a shell command can silently truncate the password that’s actually sent.
  • A leftover anonymous user account matching before your intended row, since MySQL evaluates accounts by specificity of the host pattern, and an unexpected anonymous or wildcard account can intercept the connection first.

How to fix it

  1. Confirm which account should match: SELECT user, host FROM mysql.user; (run as an account that can already connect, or via sudo mysql locally if auth_socket/skip-grant-tables allows it).
  2. Reset the password for the exact user@host pair you’re using: ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';. ALTER USER takes effect immediately — no FLUSH PRIVILEGES needed.
  3. If you’re locked out entirely, stop the service and start mysqld manually with --skip-grant-tables (MySQL 8 also turns on --skip-networking with it, so only local clients can connect). In that mode, run FLUSH PRIVILEGES; first to reload the grant tables, then ALTER USER, then restart the server normally — see the reference manual’s “How to Reset the Root Password” for your version.
  4. Grant the right host pattern if the account exists for localhost but you’re connecting remotely (or vice versa): CREATE USER 'app'@'%' IDENTIFIED BY '...'; GRANT ... ;
  5. Test with the exact host and user flags rather than defaults: mysql -h 127.0.0.1 -u app -p.
  6. If a script connects with no username at all, the mysql client on Unix falls back to your OS login name (on Windows, ODBC) — pass -u explicitly rather than relying on that default, especially when the same script runs under different accounts in different environments.

In Tablyne

Once a connection succeeds, Tablyne stores the password in your OS keychain rather than a plaintext config file, so you re-enter it only when the account’s real password changes.

Stop guessing which account matched. Download Tablyne or open the MySQL & MariaDB GUI.

Sources

Frequently asked questions

What does '(using password: YES)' vs '(using password: NO)' mean? +

It reports whether a password was supplied at all, not whether it was correct. YES means a password was sent and rejected; NO means the client tried to connect with no password, which fails against any account that has one set.

Is error 1045 the same for every host part like 'root'@'localhost' vs 'root'@'%'? +

No — MySQL accounts are keyed by user AND host together. 'root'@'localhost' and 'root'@'%' (or 'root'@'192.168.1.5') are different accounts that can have different passwords. Fixing one doesn't fix the other, and connecting from a different host than the account allows produces this same error even with the right password.

Can a firewall or wrong port cause this specific error? +

No — 1045 only happens after the client already reached the server and MySQL evaluated the account. A blocked port or unreachable host produces a different failure (a connection error, not an access-denied one), most often ERROR 2002 for a local socket or ERROR 2003 for a remote host.

Related errors