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

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


The solution:

Sometimes when you change your .env, the configs don't refresh without clear cache or restarting the server.

The error message are:

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

The database are trying to get the information from the "cached" .env configuration, you should try:

php artisan config:clear

if not solve, restart your server.

[Edit] Another NON RECOMMENDED option:

  • Go to your config\database.php
  • remove the .env configuration

And set your own credentials

'mysql' => [            'host' => '45.55.88.77',            'database' => 'prod',            'username' => 'forge',            'password' => '*********',        ],


I had the same issue, trying to install Matomo on my localhost. I thought it was my MySQL configuration but it seems it was my adblockers and adtrackers plugins in my browser (Opera). Once deactivated, it worked fine.I hope I could help...Good luck !


This file is caching some data like database configurations \bootstrap\cache\config.php. Either delete it or update it with new data.