Reputation: 58642
In my Ubuntu VM, I kept getting
SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
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)
Upvotes: 6
Views: 85208
Reputation: 393
Make sure the "database user" has all the privileges of the database (and don't forget to import the SQL file).
Edit the Database credentials in .env file and make sure to add the quotes
DB_DATABASE="dbname"
DB_USERNAME="dbusername"
DB_PASSWORD="dbpassword"
Run the following commands
composer install
php artisan config:clear
php artisan cache:clear
Browse the URL : "http://localhost/Foldername/" or "http://yourdomain.com"
Done
Upvotes: 0
Reputation: 3015
I'm also faced this issue. ENV Variable should be with in the double quotes When we used complex characters of string on .env file. Such as passwords, secrets, key and so on.
DB_PASSWORD="FDXSCHVBGFFUOVIDVKTFUVIF++++++****"
please first check this scenario.
Thank you..
Upvotes: 2
Reputation: 11
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 !
Upvotes: 1
Reputation: 71
check database port if you use wamp, login phpadmin and see Server: MySQL on top of the page.
Upvotes: 0
Reputation: 61
I think your problem is with your database and not with laravel.
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 | <-- must be % not localhost coz you want to access it remotely not locally
| debian-sys-maint | localhost |
| root | localhost |
+------------------+-------------+
8 rows in set (0.00 sec)
Hopefully this can help.
Upvotes: 0
Reputation: 41
This file is caching some data like database configurations \bootstrap\cache\config.php
. Either delete it or update it with new data.
Upvotes: 0
Reputation: 2398
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.
config\database.php
And set your own credentials
'mysql' => [
'host' => '45.55.88.77',
'database' => 'prod',
'username' => 'forge',
'password' => '*********',
],
Upvotes: 15