gijoe's avatar
Level 1

SQLSTATE[HY000] [2002] Connection refused

Im working in a mac, I have tried everything and still the error.

Note: ProductController.php works fine until trying to return database info.

This is my .env:

APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=laravel5 DB_USERNAME=root DB_PASSWORD=''

This is my database.php 'mysql' => [ 'driver' => 'mysql', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'laravel5'), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', ''),

Can't find the error please help!

0 likes
4 replies
jlrdw's avatar

Try localhost instead of 127.0.0.1 Also try stopping and restarting mysql. And clear your config.

php artisan config:clear

gijoe's avatar
Level 1

Hi @jlrdw did just that, and now it appears SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from products)

jlrdw's avatar

Are you able to connect to mySQL with phpmyadmin or another front end. And Run a simple query.

Please or to participate in this conversation.