ERROR database resource_error ai_generated true

ERROR 1040 (HY000): Too many connections

ID: database/mysql-too-many-connections

Also available as: JSON · Markdown
90%Fix Rate
92%Confidence
70Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active

Root Cause

All MySQL connection slots (max_connections, default 151) are in use. No new connections can be established including admin connections. Caused by connection leaks, missing connection pooling, or sudden traffic spikes.

generic

Workarounds

  1. 92% success Use a connection pooler like ProxySQL or MySQL Router
    Install ProxySQL and configure backend MySQL servers. Set mysql-max_connections in ProxySQL to limit backend connections while accepting more frontend connections. Applications connect to ProxySQL port instead of MySQL directly.
  2. 88% success Identify and close idle connections, fix connection leaks
    Connect as root (MySQL reserves one extra connection for SUPER users): mysql -u root -p. Run: SHOW PROCESSLIST; to see all connections. Kill idle ones: KILL <id>; Set wait_timeout and interactive_timeout to reasonable values (e.g., 300 seconds) to auto-close idle connections. Fix application code to properly close connections.

Dead Ends

Common approaches that don't work:

  1. Setting max_connections extremely high (e.g., 10000) without corresponding OS and hardware tuning 80% fail

    Each MySQL connection uses a thread with its own memory allocation. High max_connections without increasing open_files_limit, thread stack, and available RAM leads to OOM or 'Can't create a new thread' errors.

  2. Rapidly restarting MySQL to reset connections 85% fail

    Restarting kills all connections and in-flight transactions abruptly. Without fixing the root cause, connections exhaust again within minutes. Repeated restarts cause data corruption risk with InnoDB recovery.

Error Chain

Leads to:
Preceded by:
Frequently confused with: