local.ERROR: SQLSTATE[HY000] [2002] Connection refused

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Error:-

local.ERROR: SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select count(*) as aggregate from `profiles`) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select count(*) as aggregate from `profiles`) at /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:822)
[stacktrace]
#0 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(976): Illuminate\\Database\\Connection->runQueryCallback('select count(*)...', Array, Object(Closure))
#1 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(955): Illuminate\\Database\\Connection->tryAgainIfCausedByLostConnection(Object(Illuminate\\Database\\QueryException), 'select count(*)...', Array, Object(Closure))
#2 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(778): Illuminate\\Database\\Connection->handleQueryException(Object(Illuminate\\Database\\QueryException), 'select count(*)...', Array, Object(Closure))
#3 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(407): Illuminate\\Database\\Connection->run('select count(*)...', Array, Object(Closure))
#4 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2751): Illuminate\\Database\\Connection->select('select count(*)...', Array, true)
#5 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2740): Illuminate\\Database\\Query\\Builder->runSelect()
#6 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3294): Illuminate\\Database\\Query\\Builder->Illuminate\\Database\\Query\\{closure}()
#7 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2739): Illuminate\\Database\\Query\\Builder->onceWithColumns(Array, Object(Closure))
#8 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2904): Illuminate\\Database\\Query\\Builder->get()
#9 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2863): Illuminate\\Database\\Query\\Builder->runPaginationCountQuery(Array)
#10 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2770): Illuminate\\Database\\Query\\Builder->getCountForPagination()
#11 /opt/lampp/htdocs/devopsschool/ds-company-ms/app/Http/Controllers/ProfileController.php(258): Illuminate\\Database\\Query\\Builder->paginate(30)
#12 /opt/lampp/htdocs/devopsschool/ds-company-ms/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\ProfileController->getAllListOfCompany()

Solution :-

Step 1:- Check out your error If it says that your data base is not connected then please connect your database.

Step 2:- In my case there is and error in DB_HOST port is not matched.

DB_HOST=127.0.0.1

Step 3:- Change your DB_HOST port to Localhost. Like given below

DB_HOST=localhost

Step 4:- After adding this you have to clear cache in your project by using below command:

php artisan c:cache

Step 5:- Now you can refresh your page. and your issue is resolved.

Issue Resolved.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x