The application gets "Too many connections" from MySQL. How do you fix it?

IntermediateTroubleshootingMySQL
Answer

Short answer

MySQL has reached max_connections. Find who holds the connections (usually the app's connection pools across many pods, or connections that are never closed), fix the cause (pool sizes, leaks, idle timeouts), and only then consider raising the limit or adding a proxy.

Investigate

SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected';
SHOW STATUS LIKE 'Max_used_connections';
SELECT user, host, COUNT(*) FROM information_schema.processlist GROUP BY user, host ORDER BY 3 DESC;
SELECT * FROM information_schema.processlist WHERE command = 'Sleep' AND time > 300;   -- idle for 5+ min

Usual causes and fixes

Cause Fix
Pods × pool size > max_connections (after scaling out) Smaller pools; factor in HPA max replicas
Connection leak (not returned to pool) Fix code; set pool leak detection
Long idle connections wait_timeout lower; pool idleTimeout / maxLifetime
Slow queries holding connections Fix the queries (often the real root cause)
Too many app instances ProxySQL or RDS Proxy to multiplex

Immediate relief

SET GLOBAL max_connections = 500;    -- if memory allows; on RDS change the parameter group

Each connection uses memory, so raising the limit blindly can cause out-of-memory.

What to say in the interview

"I check Threads_connected versus max_connections and group the processlist by user and host to see which service holds them. Usually it's pool size multiplied by replicas, leaks or slow queries. I fix pools and timeouts, use RDS Proxy or ProxySQL at scale, and raise max_connections only within memory limits."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MySQL basics

More on MySQL