Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused laravel laravel

Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused


Open localhost/phpmyadmin and find a tab called User accounts.

Find the root user and set its password in your .env and also don't forget to create the database named laravel if it doesn't exist

Then you can clear config cache

php artisan config:clear

And migrate

php artisan migrate


I've come across this Error too by building up a new project with Laravel running in docker-compose for development.

My solution was to compare the prebuild .env-File with the actual credentials I used for building the database container.Especially I was using DB_HOST=127.0.0.1 instead of the correct service name of my docker-compose setup: DB_HOST=mysql


Just simple step i follow and solved

open .env file

change DB_HOST = 127.0.0.1 to localhost

done