MySQL

Diagnosing MySQL Connection Saturation: Too Many Connections Fix

Systematically diagnose and fix MySQL 'Too many connections' errors. Learn to identify connection leaks, tune wait_timeout, and implement ProxySQL pooling.

JusDB Team
February 7, 2025
Updated June 20, 2026
5 min read

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

sql
-- 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

sql
-- 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;
Note: Long-sleeping connections are usually connection leaks in the application. Check that your ORM or connection pool is properly releasing connections.

Tuning max_connections

sql
-- Temporarily raise limit (requires SUPER)
SET GLOBAL max_connections = 500;

-- Check peak ever reached
SHOW STATUS LIKE 'Max_used_connections';
Warning: Each MySQL connection consumes ~1 MB RAM. Setting 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

sql
-- 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.processlist immediately when connections spike
  • Long-sleeping connections signal application connection leaks
  • Lower wait_timeout to 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.

Share this article

JusDB Team

Official JusDB content team

Keep reading

MySQL Explained (2026): InnoDB, 8.4 LTS, Replication & Production Patterns

Everything you need to know about MySQL: storage engines, replication topologies, performance tuning, and cloud deployment. From basics to advanced optimization.

MySQL5 minMay 13, 2026
Read

MySQL binlog Retention, Rotation & Purge: Production Guide (2026)

Configure MySQL binlog retention safely: binlog_expire_logs_seconds, manual purging rules, AWS RDS retention, and the disk-exhaustion failure mode you should monitor for.

MySQL10 minMay 9, 2026
Read

MySQL "Communications Link Failure": Fix wait_timeout, HikariCP & All 8 Timeout Variables

MySQL wait_timeout, net_read_timeout, innodb_lock_wait_timeout and max_execution_time — production tuning rules and the HikariCP alignment trick that prevents 'communications link failure' errors.

MySQL6 minMay 9, 2026
Read