MySQL ERROR 1040 (08004): Too many connections
MySQL reached max_connections and refuses new clients.
Meaning
Each client connection uses memory, so MySQL caps them (default 151). Leaking connections, unbounded worker counts, persistent connections from many PHP-FPM children, or slow queries piling up exhaust the limit. Shared hosting often has a per-user cap (max_user_connections, error 1203).
Common causes
- Connections not closed / connection leaks
- Too many app workers each holding a pool
- Slow queries keeping connections busy so new ones pile up
- Persistent connections × many PHP-FPM processes
- Per-user limit on shared hosting
⚡ Quick fix
- See who is connected:
SHOW PROCESSLIST; - Fix slow queries causing pile-ups
- Right-size pools: workers × pool size < max_connections
- Raise max_connections only if RAM allows
Detailed fix by platform
MySQL
- Inspect and adjust:sql
SHOW VARIABLES LIKE 'max_connections'; SHOW STATUS LIKE 'Max_used_connections'; SELECT user, host, COUNT(*) FROM information_schema.processlist GROUP BY user, host ORDER BY 3 DESC; SET GLOBAL max_connections = 300; -- also persist in my.cnf
Node.js
- Create ONE pool per process (e.g.
mysql2.createPool({ connectionLimit: 10 })), not a connection per request.
How to diagnose
- Usage — Max_used_connections vs max_connections
- Who — Which user/host holds most connections?
- State — Many in Sleep (leak) or Query (slow)?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026