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

**Code:** `SQLSTATE[HY000] [1045] Access denied for user` · **Category:** Laravel · **Seen on:** Laravel, PHP, MySQL

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/laravel/sqlstate-hy000-1045-access-denied)
