SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) . DB_HOST set to localhost
To be honest while working on laravel 6 i also faced this issue many times and probably was unable to figure out the solution i tried commands like
php artisan config:cache
and php artisan config:clear
but these two commands didn't help.
To come over this issue you have to execute the all the below commands:
php artisan route:cache
php artisan route:clear
php artisan config:cache
php artisan config:clear
php artisan optimize
Note: Make sure in .env
you have put db_password
and it is not null and also check if your db_password
uses any special character always enclose them in ""
Example:
DB_PASSWORD="%123456%"
To debug this issue you can also create a test route and then dump .env
variable there to check if they have the correct values or not?
Route::get('/test/env', function () {
dd(env('DB_DATABASE')); // dump db variable value one by one
});
Hope it helps.
Thanks
Note: Please Make sure to restart your server.
Make sure your DB credential and DB Host is set correctly :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"
If you have not set any db password the put
DB_PASSWORD=""
The problem is that the project made a cache file 'config.php' must be deleted in order to allow the system to restart and you can do so by accessing this file and deleting it
bootstrap/cache/config.php