Sail: getaddrinfo failed for host mysql Laravel Origin: Application & API OSI layer 7 · Application Last updated 4 Nov 2026

Laravel Sail: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution

Commands run outside the Sail container (on the host) try to resolve the Docker service name mysql, which only exists inside the Docker network.

Exact message you may see php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolutiongetaddrinfo for mysql failed: Name or service not knownSQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (sail)Sail mysql host not found
Seen on: Laravel PHP Docker

Meaning

Run artisan inside the container: ./vendor/bin/sail artisan migrate. If you want to run from the host, set DB_HOST=127.0.0.1 and use the forwarded port (FORWARD_DB_PORT). Also make sure containers are up (sail up -d) and MySQL finished initialising.

Common causes

  • Running php artisan migrate on the host with DB_HOST=mysql
  • Containers not started
  • MySQL container still booting
  • Port conflicts (3306 already used)
  • Wrong network

⚡ Quick fix

  1. Use ./vendor/bin/sail artisan ...
  2. Or set DB_HOST=127.0.0.1 for host commands
  3. ./vendor/bin/sail up -d and wait for health

Detailed fix by platform

Docker

  1. ./vendor/bin/sail up -d && ./vendor/bin/sail artisan migrate

How to diagnose

  1. Where — Host or container?
  2. DB_HOST — Service name vs localhost?
  3. Containers — Running?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

403 This action is unauthorized — Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized. (Laravel)403 This action is un…Attempt to read property "x" on null — Laravel/PHP 8: ErrorException: Attempt to read property "name" on null (Laravel)Attempt to read prope…Command "x" is not defined — Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these? (Laravel)Command "x" is not de…Laravel: Allowed memory size exhausted (request) — Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework (Laravel)Laravel: Allowed memo…PDOException: could not find driver — Laravel: Illuminate\Database\QueryException: could not find driver (SQL: select * from information_schema.tables) (Laravel)PDOException: could n…port is already allocated — Docker: Bind for 0.0.0.0:80 failed: port is already allocated (Docker)port is already alloc…Redis in Docker loses data on restart (no volume) — Docker: Redis data gone after container restart — dump.rdb not persisted to a volume (Redis)Redis in Docker loses…SQLSTATE[HY000] [2002] Connection refused — Laravel: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from sessions) / php_network_getaddresses: getaddrinfo failed (Laravel)SQLSTATE[HY000] [2002…Sail: get…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.