If you see the error:
“ERROR 1040 (08004): Too many connections”
your MySQL server has reached itsmax_connections
limit.
What Causes This?
- Application leaking connections (not closing)
- Slow queries blocking connections
- Connection pool misconfigured
- Low
max_connections
default (151)
How to Fix
1. Check Current Connection Usage
SHOW STATUS WHERE variable_name = 'Threads_connected';
SHOW VARIABLES LIKE 'max_connections';
2. Temporarily Increase Limit
SET GLOBAL max_connections = 500;
3. Make It Persistent
Edit my.cnf
:
[mysqld]
max_connections = 500
4. Find Idle/Hanging Connections
SHOW PROCESSLIST;
Kill problematic threads or fix your app logic.