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.
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] 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
mysqlordb) - Wrong DB_PORT (3306 vs mapped host port)
- Hostname doesn't resolve (typo, Sail not up)
- Cached config using old host
⚡ Quick fix
- Start MySQL:
sudo systemctl start mysql - In Sail:
DB_HOST=mysqland./vendor/bin/sail up -d php artisan config:clear
Detailed fix by platform
Linux
nc -vz 127.0.0.1 3306; Sail:./vendor/bin/sail ps
How to diagnose
- Server — Running?
- Host/port — Match environment?
- 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:
Similar errors
- ConnectionRefusedError [Errno 111] (SMTP) Python: ConnectionRefusedError: [Errno 111] Connection refused — smtplib connect to localhost:25
- Laravel: Allowed memory size exhausted (request) Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework
- Nodemailer: ETIMEDOUT / ECONNECTION Nodemailer: Error: connect ETIMEDOUT 142.250.27.108:465 (code: 'ETIMEDOUT', command: 'CONN')
Most viewed in Laravel
- MassAssignmentException Laravel: Illuminate\Database\Eloquent\MassAssignmentException: Add [x] to fillable property to allow mass assignment
- The GET method is not supported for route Laravel: The GET method is not supported for route x. Supported methods: POST (MethodNotAllowedHttpException)
- Route [login] not defined Laravel: Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 4 Nov 2026