justDan
justDan

Reputation: 2335

Laravel App - SQLSTATE[HY000] [2002] Connection refused

I recently was given a project to work on that is built with laravel 8. I don't have much experience with laravel and the previous developer didn't leave much documentation to say how to start the app properly so I've been reading up on what to do to get started. I cloned the project, ran composer install and renamed .env.example to .env. From here the little documentation written from the previous dev says to run php artisan migrate. However when running that, I get an error SQLSTATE[HY000] [2002] Connection refused. I have seen a few posts on this site with some trouble shooting techniques, but so far nothing is working for me yet. My current .env DB section looks like:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

This is how it came by default and when I ran php artisan migrate I got SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known. I read around and saw that some folks changed DB_HOST to localhost instead of mysql. After I did that is when I started to get the connection refused error and now I'm a little lost. How can I find the proper host/port on Mac OS so I can run php artisan migrate?

Upvotes: 0

Views: 204

Answers (1)

Vishal_VE
Vishal_VE

Reputation: 2127

it's because of you did not provide any database name in the .env file, before migration it is necessary to provide database name with their credentials

Please Create a database in phpmyadmin and fill out require parameter of database in env Example. created database name test in phpmyadmin then code will be like this

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME="database username here"
DB_PASSWORD="database password here"

If you do not have any password for database leave blank password field Let me know if you have any confusion

Upvotes: 1

Related Questions