SQLSTATE[HY000] [2002] Connection refused Laravel Origin: Application & API Last updated 4 Nov 2026

Laravel: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from sessions) / php_network_getaddresses: getaddrinfo failed

Laravel can't open a network connection to the database host and port from .env.

Exact message you may see SQLSTATE[HY000] [2002] Connection refusedSQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not knownSQLSTATE[HY000] [2002] No such file or directorySQLSTATE[HY000] [2002] Connection timed outIlluminate\Database\QueryException SQLSTATE[HY000] [2002]
Seen on: Laravel PHP MySQL

Meaning

MySQL isn't running, DB_HOST/DB_PORT are wrong, or you're in Docker/Sail where the host is the service name (mysql), not 127.0.0.1. getaddrinfo failed means the host name doesn't resolve. Clear config cache after editing .env.

Common causes

  • MySQL not running or port blocked
  • Using 127.0.0.1 inside Docker (should be service name mysql or db)
  • Wrong DB_PORT (3306 vs mapped host port)
  • Hostname doesn't resolve (typo, Sail not up)
  • Cached config using old host

⚡ Quick fix

  1. Start MySQL: sudo systemctl start mysql
  2. In Sail: DB_HOST=mysql and ./vendor/bin/sail up -d
  3. php artisan config:clear

Detailed fix by platform

Linux

  1. nc -vz 127.0.0.1 3306 ; Sail: ./vendor/bin/sail ps

How to diagnose

  1. Server — Running?
  2. Host/port — Match environment?
  3. Docker — Service name used?

🔧 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):

ConnectionRefusedError [Errno 111] (SMTP) — Python: ConnectionRefusedError: [Errno 111] Connection refused — smtplib connect to localhost:25 (Email / SMTP)ConnectionRefusedErro…ECONNRESET / Connection reset by peer on idle Redis connection — Redis: Error: read ECONNRESET / redis.exceptions.ConnectionError: Connection reset by peer after idle time (Redis)ECONNRESET / Connecti…Error: connect ECONNREFUSED 127.0.0.1:6379 — Redis: Error: connect ECONNREFUSED 127.0.0.1:6379 / Could not connect to Redis at 127.0.0.1:6379: Connection refused (Redis)Error: connect ECONNR…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…Nodemailer: ETIMEDOUT / ECONNECTION — Nodemailer: Error: connect ETIMEDOUT 142.250.27.108:465 (code: 'ETIMEDOUT', command: 'CONN') (Email / SMTP)Nodemailer: ETIMEDOUT…PDOException: could not find driver — Laravel: Illuminate\Database\QueryException: could not find driver (SQL: select * from information_schema.tables) (Laravel)PDOException: could n…Redis connection refused (Laravel) — Laravel: Predis\Connection\ConnectionException: Connection refused [tcp://127.0.0.1:6379] / RedisException: Connection refused (Laravel)Redis connection refu…Redis TLS: SSL handshake error / protocol mismatch — Redis: Error: write EPROTO ... SSL routines:ssl3_get_record:wrong version number / Connection reset by peer (TLS vs plaintext) (Redis)Redis TLS: SSL handsh…SQLSTATE[…

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.