SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
Solution 1
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' => '*********',
],
Solution 2
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 !
code-8
I'm B, I'm a cyb3r-full-stack-web-developer. I love anything that is related to web design/development/security, and I've been in the field for about ~9+ years. I do freelance on the side, if you need a web project done, message me. ;)
Updated on February 14, 2022Comments
-
code-8 over 2 years
In my Ubuntu VM, I kept getting
SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
update
I have configured my database like this in my .env file
DB_HOST=45.55.88.57 DB_DATABASE=b-prod DB_USERNAME=root DB_PASSWORD=********* UNIX_SOCKET=/var/run/mysqld/mysqld.sock
It works perfectly.
But when I use
DB_HOST=45.55.88.57 DB_DATABASE=b-prod DB_USERNAME=b <---------------------------------------------- DB_PASSWORD=********* UNIX_SOCKET=/var/run/mysqld/mysqld.sock
I didn't work.
What else I should look into to prevent this ?
I have a feeling that I have the wrong password.
How do I test my database password ? DB_PASSWORD=********* ?
This is all user I have
mysql> SELECT User,Host FROM mysql.user; +------------------+-------------+ | User | Host | +------------------+-------------+ | root | % | | root | 127.0.0.1 | | root | 45.55.88.57 | | root | ::1 | | root | b | | b | localhost | | debian-sys-maint | localhost | | root | localhost | +------------------+-------------+ 8 rows in set (0.00 sec)