Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
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.

over 4 years ago · Santiago Trujillo
6 answers
Answer question

0

I had this same issue after creating a second sail project in my docker. It wasn't (still isn't) accepting the sail username or password but I could go in with root which gave me the error you gave above. I went to the Desktop Docker app, clicked the running container, found the mysql portion and ran the CLI, typed mysql and then ran the query CREATE DATABASE yourdatabasename; migration ran perfectly fine.

over 4 years ago · Santiago Trujillo Report

0

Changing DB_USERNAME from sail to root worked for me. I guess sail did not have the required privileges.

DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=root # changed from sail
DB_PASSWORD=password
over 4 years ago · Santiago Trujillo Report

0

if you want run mysql in different port for example 3307 like below

ports:
  - 3307:3306

you should add FORWARD_DB_PORT environment variable to .env file like this

DB_PORT=3306 // this is for container port
FORWARD_DB_PORT=3307 // this is for local port
over 4 years ago · Santiago Trujillo Report

0

First off stop all services using brew especially MySQL

brew services stop MySQL

in your docker-yaml file:

laravel.test
   ports:
     - '70:80'
mysql:
   ports:
     - '3456:3306'

Now run your sail artisan migrate command.

this should solve your problem.

over 4 years ago · Santiago Trujillo Report

0

Maybe you should match the environment variables of .env.testing, since, as willpercey-gb says, the sail:install command updates the environment variables of .env, but not of .env.testing.

over 4 years ago · Santiago Trujillo Report

0

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!