Scaleup Infotech
Scaleup Infotech.
Back to Blog
Bug Fixes7 min read

Fix 'SQLSTATE[HY000] [2002] Connection refused' in Laravel

Scaleup Infotech

Scaleup Infotech

Software & Marketing Agency

May 26, 2026
Fix 'SQLSTATE[HY000] [2002] Connection refused' in Laravel
LaravelMySQLDockerDatabase

[2002] Connection refused means your app reached a network address but nothing accepted the connection there. The database is down, on a different host, or — most often in Docker — you used the wrong hostname.

The Error

SQLSTATE[HY000] [2002] Connection refused

Cause 1: MySQL Isn't Running

bash
# Is it up?
sudo service mysql status
# Start it
sudo service mysql start

Cause 2: Wrong Host in Docker

Inside a Docker container, 127.0.0.1 points at the container itself, not your database container. Use the service name from docker-compose.yml as the host:

bash
# .env — use the compose service name, not 127.0.0.1
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=app
DB_USERNAME=root
DB_PASSWORD=secret

Cause 3: Wrong Port

Local MySQL defaults to 3306, but MAMP uses 8889 and some setups remap it. Confirm what is actually listening:

bash
lsof -i -P | grep mysql

After Editing .env

Always run php artisan config:clear. Laravel caches config, so .env changes are ignored until you clear it — a classic 'I fixed it but it still fails' trap.

Share this article:

Keep Reading

Ready to implement these ideas?

Work With Scaleup Infotech