Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda