When MySQL hits max_connections, new connections receive Too many connections errors and your application grinds to a halt. Here is how to diagnose and fix connection saturation.
Symptoms
ERROR 1040 (HY000): Too many connections- Application timeouts spiking
- MySQL thread count pegged at
max_connections
Immediate Diagnosis
-- How many connections are open right now?
SHOW STATUS LIKE 'Threads_connected';
-- What is the configured limit?
SHOW VARIABLES LIKE 'max_connections';
-- Who is using connections?
SELECT user, host, db, command, time, state
FROM information_schema.processlist
ORDER BY time DESC
LIMIT 50;Find Connection Hogs
-- Count by user and host
SELECT user, host, count(*) AS cnt
FROM information_schema.processlist
GROUP BY user, host
ORDER BY cnt DESC;
-- Long-running sleeping connections (connection leaks)
SELECT id, user, host, time
FROM information_schema.processlist
WHERE command = 'Sleep' AND time > 300
ORDER BY time DESC;Tuning max_connections
-- Temporarily raise limit (requires SUPER)
SET GLOBAL max_connections = 500;
-- Check peak ever reached
SHOW STATUS LIKE 'Max_used_connections';max_connections = 2000 on a 4 GB server will cause OOM kills. Use a connection pooler (ProxySQL, PgBouncer) instead of simply raising the limit.wait_timeout and interactive_timeout
-- Reduce idle connection lifetime
SET GLOBAL wait_timeout = 60;
SET GLOBAL interactive_timeout = 60;Long-Term Fix: ProxySQL Connection Pooling
The real fix for connection saturation is a connection pooler in front of MySQL. ProxySQL multiplexes thousands of app connections onto a smaller pool of MySQL connections, keeping Threads_connected low regardless of application concurrency.
Key Takeaways
- Check
information_schema.processlistimmediately when connections spike - Long-sleeping connections signal application connection leaks
- Lower
wait_timeoutto reclaim idle connections faster - Deploy ProxySQL as the permanent fix — don't just raise
max_connections
JusDB Can Help
Connection saturation incidents require both immediate triage and long-term architecture changes. JusDB engineers can diagnose your connection patterns and right-size your pooling layer.