close

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

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused Error Occurs?

Today I get the following error Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused in php.

How To Solve Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused Error ?

  1. How To Solve Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused Error ?

    To Solve Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused Error 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

  2. Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused

    To Solve Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused Error 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

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

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment