SQLSTATE[HY000] [1045] Access denied for user Laravel Origin: Application & API OSI layer 7 · Application Last updated 4 Nov 2026

Laravel: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES)

MySQL rejected the username/password configured in Laravel's .env.

Exact message you may see SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES)SQLSTATE[HY000] [1045] Access denied for userAccess denied for user 'root'@'localhost' (using password: NO) LaravelIlluminate\Database\QueryException SQLSTATE[HY000] [1045]
Seen on: Laravel PHP MySQL

Meaning

Check DB_USERNAME, DB_PASSWORD, DB_HOST and DB_DATABASE. Special characters in passwords need quotes in .env. After changing .env, clear cached config (php artisan config:clear), otherwise Laravel keeps using old values. Also verify the MySQL user can connect from that host.

Common causes

  • Wrong credentials in .env
  • Config cached with old values
  • Password with # or spaces not quoted
  • User lacks privileges for the host ('user'@'localhost' vs %)
  • Using root with auth_socket plugin

⚡ Quick fix

  1. Test with mysql -u USER -p -h HOST DB
  2. php artisan config:clear
  3. Quote the password in .env: DB_PASSWORD="p#ss word"

Detailed fix by platform

Laravel

  1. php artisan config:clear && php artisan tinker --execute="DB::connection()->getPdo();"

How to diagnose

  1. Credentials — Work in mysql client?
  2. Cache — config cleared?
  3. Host — Grants for that host?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Command "x" is not defined — Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these? (Laravel)Command "x" is not de…env() returns null (config cached) — Laravel: .env changes ignored / env('X') returns null after php artisan config:cache (Laravel)env() returns null (c…Laravel: Allowed memory size exhausted (request) — Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework (Laravel)Laravel: Allowed memo…PDOException: could not find driver — Laravel: Illuminate\Database\QueryException: could not find driver (SQL: select * from information_schema.tables) (Laravel)PDOException: could n…SQLSTATE[23000]: Integrity constraint violation — Laravel: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'x@example.com' for key 'users_email_unique' (Laravel)SQLSTATE[23000]: Inte…SQLSTATE[42S22]: Column not found — Laravel: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'status' in 'field list' (Laravel)SQLSTATE[42S22]: Colu…SQLSTATE[HY000] [2002] Connection refused — Laravel: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from sessions) / php_network_getaddresses: getaddrinfo failed (Laravel)SQLSTATE[HY000] [2002…SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client — Laravel: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client [caching_sha2_password] (Laravel)SQLSTATE[HY000] [2054…SQLSTATE[…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.