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

**Code:** `SQLSTATE[HY000] [2002] Connection refused` · **Category:** Laravel · **Seen on:** Laravel, PHP, MySQL

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/laravel/sqlstate-hy000-2002-connection-refused)
