Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused

I am new in Laravel development. I have updated Xampp to 7.3.11 on my Mac Mojave 10.14.6. In Laravel project when I hit php artisan migrate command I got following error.

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

When I start Xampp service, my admin panel run on http://127.0.0.1:8080/phpmyadmin. My working project in Laravel is also not connecting with database saying connection refused. I tried by changing DB_Port and DB_Host in .env file. I tried by clearing cache.

Any Help will be appreciated.

My .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

Solution 1:

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

Solution 2:

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

Solution 3:

Just simple step i follow and solved

open .env file

change DB_HOST = 127.0.0.1 to localhost

done