Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Sail Database Connection Refused Error

I have created a new laravel project in laravel 8. I have set up Sail installation correctly, everything working fine for database connection in local but when I try to connect my database using sail it gives me an error

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

I have already cleared my config and cache files.

like image 404
Rutul Thakkar Avatar asked Jan 05 '21 09:01

Rutul Thakkar


1 Answers

I was researching the same problem and found this.

https://github.com/laravel/sail/blob/7457004969dd62fa727fbc596bb2accccb1409a5/src/SailServiceProvider.php#L31

The code shows an artisan command added by laravel sail - sail:install which overwrites your .env file host variables with service names.

I changed DB_HOST from 127.0.0.1 to mysql and it was fixed

like image 86
willpercey-gb Avatar answered Sep 20 '22 11:09

willpercey-gb