Skip to content
ERROR 1040 (HY000): Too many connections

ERROR 1040 (HY000): Too many connections

DodaTech 2 min read

The error “ERROR 1040 (HY000): Too many connections” means the MySQL server has reached the maximum number of simultaneous client connections allowed by the max_connections variable.

What It Means

MySQL allocates one thread per client connection. The max_connections system variable (default 151 in MySQL 8.0) limits how many concurrent clients can connect. When the limit is hit, new connection attempts receive this error immediately.

Why It Happens

  • Your application creates a new connection for every request and does not close them.
  • The connection pool size is too large for the number of application instances.
  • A previous deployment left stale connections open (common in containerized environments).
  • MySQL is shared across multiple services and the combined usage exceeds the limit.
  • A single misconfigured client is rapidly opening and leaking connections.
  • The server has insufficient resources to handle the connection load.

How to Fix It

1. Check the current connection count

SHOW STATUS LIKE 'Threads_connected';

2. Increase max_connections

SET GLOBAL max_connections = 500;

For a permanent change, edit my.cnf:

[mysqld]
max_connections = 500

3. Kill idle connections

SHOW FULL PROCESSLIST;
KILL CONNECTION <thread_id>;

4. Kill all connections for a specific user

SELECT CONCAT('KILL ', id, ';') FROM information_schema.processlist
WHERE user = 'appuser';

5. Set a connection timeout

[mysqld]
wait_timeout = 600
interactive_timeout = 600

6. Optimize application connection pooling

# Example with Python's SQLAlchemy
engine = create_engine('mysql://user:pass@localhost/db',
                       pool_size=10, max_overflow=20)

FAQ

What is the default max_connections in MySQL 8.0?
The default is 151. This was reduced from earlier versions to conserve memory. You can increase it based on your server’s RAM — each connection uses approximately 10 MB of memory.
How do I monitor connection usage over time?
Use SHOW GLOBAL STATUS LIKE 'Threads_connected'; and SHOW GLOBAL STATUS LIKE 'Connections';. Set up a monitoring tool like Prometheus + mysqld_exporter to track connection trends and alert before the limit is reached.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro