Fix this error
SQLSTATE[HY000] [1045] Access denied for user
Dasun Kalupahana 323 views
The error
Error
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
Why it happens
The database server is running, but it rejected the username or password, or that user is not allowed to connect from this host.
DB_USERNAME/DB_PASSWORDin.envare wrong.- The password contains
#or spaces and is not quoted, so.envcuts it off. - On shared hosting (cPanel) the user name has a prefix such as
account_user, or the user was never added to the database. - The config is cached with old values.
How to fix it
- Check the credentials in
.env. Quote passwords that contain special characters:DB_PASSWORD="p#ss word". - On cPanel, use the full prefixed names and add the user to the database (MySQL Databases → Add User To Database, all privileges).
- Run
php artisan config:clear. - If you manage MySQL yourself, create the user and grant access (below).
CREATE USER 'app'@'localhost' IDENTIFIED BY 'strong-password';
GRANT ALL PRIVILEGES ON laravel.* TO 'app'@'localhost';
FLUSH PRIVILEGES;
Still stuck? Send us the full error and what you tried. We add the answers here.
Learn more on the blog
MySQL
PostgreSQL vs MySQL Performance: Real Benchmarks Compared
Last updated: 7 November 2026. See the update log at the end."Which...
8 min read
PHP
How to Detect and Fix PHP Memory Leaks
Last updated: 5 November 2026. See the update log at the end.In...
9 min read
Docker
Docker Build Too Slow? 10 Ways to Speed It Up
A slow Docker build usually has one of a few causes: you...
8 min read