Error Reference › SQL / Database
SQL / Database

Access denied for user (MySQL 1045)

MySQL rejected the login — the user, password, or host isn't accepted.

What it looks like

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

What does "Access denied for user (MySQL 1045)" mean?

Returned by the MySQL or MariaDB server when a login is rejected. The message shows the user and the host MySQL thinks you are connecting from, and whether a password was sent — each of those is a clue.

What causes "Access denied for user (MySQL 1045)"?

  • Wrong username or password.
  • The user isn't allowed from this host.
  • Privileges not granted to that database.

How do I confirm the cause?

  1. Read the user@host in the message: MySQL treats app@localhost and app@'%' as different accounts with different passwords.
  2. “using password: NO” means no password reached the server — the config value is empty or not being loaded.
  3. Log in with the same credentials using the mysql command-line client to separate a credentials problem from an app-config problem.

How do I fix "Access denied for user (MySQL 1045)"?

  • Verify the credentials in your config/.env.
  • GRANT the user access from the right host ('user'@'host').
  • Confirm the database exists and the user has privileges.

How do I stop it happening again?

  • Keep database credentials in one environment file per environment and load them the same way everywhere.
  • Create app users with an explicit host and only the privileges they need (GRANT … ON appdb.*).
Got a different error? Paste it into the Explain This Error tool → Identifies the family and the fix — runs locally, nothing uploaded.

Related errors