Laravel: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES)
MySQL rejected the username/password configured in Laravel's .env.
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] 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
- Test with
mysql -u USER -p -h HOST DB php artisan config:clear- Quote the password in .env:
DB_PASSWORD="p#ss word"
Detailed fix by platform
Laravel
php artisan config:clear && php artisan tinker --execute="DB::connection()->getPdo();"
How to diagnose
- Credentials — Work in mysql client?
- Cache — config cleared?
- 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:
Similar errors
- Command "x" is not defined Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these?
- env() returns null (config cached) Laravel: .env changes ignored / env('X') returns null after php artisan config:cache
- Laravel: Allowed memory size exhausted (request) Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework
Most viewed in Laravel
- MassAssignmentException Laravel: Illuminate\Database\Eloquent\MassAssignmentException: Add [x] to fillable property to allow mass assignment
- The GET method is not supported for route Laravel: The GET method is not supported for route x. Supported methods: POST (MethodNotAllowedHttpException)
- 403 This action is unauthorized Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized.
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 4 Nov 2026