Back to Error Center
Connection timed out
Error Message
SQLSTATE[HY000] [2002] Connection timed out
Cause
The database server is unreachable within the configured timeout. Common with remote databases, network issues, or firewall blocking.
Solution
Check network connectivity to the database server. Verify firewall rules. Check DB_HOST and DB_PORT. Increase connection timeout in PHP config.
Code Example
Fix
# Test network connectivity
telnet db-server 3306
ping db-server
# Check .env for correct host
DB_HOST=your-db-server.com
DB_PORT=3306
# Increase timeout in my.cnf
connect_timeout = 60
# PHP config
mysqli.default_connect_timeout = 60
Debugging Steps
- Test network connectivity to the database server
- Check firewall rules on both client and server
- Verify DB_HOST and DB_PORT
- Check for DNS resolution issues
Prevention
Use connection timeouts appropriate for your network. Monitor database server availability. Consider read replicas for geographic distribution.