Menu

MySQL Error 1040: Too Many Connections

Recover from MySQL Error 1040 with an administrator connection, inspect sessions, and size application pools against max_connections.

Posted on By Updated on
On this page

MySQL Error 1040 (08004, ER_CON_COUNT_ERROR) means the server has no ordinary client connection slot available for a new connection. The active global max_connections value controls this limit. See the MySQL 8.4 error reference and Too many connections guidance.

Check the active limit and current connection count

From an existing connection, inspect the open connection count and the server limits:

SHOW GLOBAL STATUS
WHERE Variable_name IN (
  'Threads_connected',
  'Max_used_connections',
  'Connection_errors_max_connections'
);
SHOW GLOBAL VARIABLES
WHERE Variable_name IN ('max_connections', 'max_user_connections');

Threads_connected is the current snapshot. Max_used_connections is the highest simultaneous connection count since the server started, but FLUSH STATUS resets it to the current number of open connections. It is not a rolling time-series metric. Connection_errors_max_connections counts new connection attempts refused because the global limit was reached. Record that counter before and after an incident: an increase confirms refusals during that interval, while a nonzero value alone may come from an earlier incident. FLUSH STATUS can also reset global status counters, so check whether it ran during the comparison period. A current Threads_connected reading below max_connections does not rule out a burst that has already subsided. If you have permission to inspect other sessions, SHOW PROCESSLIST can help identify which accounts and applications hold connections. Without the PROCESS privilege, most accounts can see only their own sessions. Process-list output may contain SQL text, so share it only with the appropriate administrator. See the status-variable reference, FLUSH STATUS behavior, and process-list access rules.

MySQL permits one extra connection beyond max_connections for an account with CONNECTION_ADMIN (or the deprecated SUPER) privilege. That slot is for administration, not extra application capacity. If you have a dedicated administrator account with this privilege, use it to connect and inspect sessions even when ordinary slots are full:

mysql --host=db.example.com --user=db_admin --password

Enter the password at the prompt; do not put it directly in the command. On a managed database, the provider may control this privilege or offer its own query console, so use the provider’s documented admin access path. If you cannot reach the server or do not have an administrator account, ask the database administrator or provider to inspect active sessions. See MySQL’s handling of too many connections and the CONNECTION_ADMIN privilege.

After connecting, review full process details and identify a specific stale session before taking action:

SHOW FULL PROCESSLIST;

The PROCESS privilege is needed to see other users’ threads. If you confirm a particular connection is safe to close, terminate only that connection:

KILL CONNECTION 12345;

Replace 12345 with its process-list ID. Terminating a connection can roll back its active transaction and requires suitable privileges; do not kill sessions based only on their age. See the process-list access rules and KILL statement.

Estimate application pool capacity

Use the active max_connections value reported by the server and the peak number of ordinary connections used by other workloads. Exclude the application pools you are sizing and any privileged administrative connection from the “other workloads” count.

MySQL connection pool budget estimator

This estimator models classic-protocol connections controlled by max_connections. It runs in your browser and does not connect to MySQL.

Enable JavaScript to calculate this locally. Compare pool instances × maximum connections per pool with max_connections − other ordinary connections.

The estimate is a planning check, not a target to fill every slot. It does not measure live use, account for per-user caps, or model MySQL X Protocol connections.

To choose a per-instance pool maximum across replicas and validate it with load testing, see How to Size a MySQL Connection Pool.

Reduce connection demand before raising the limit

Check the maximum pool size across all application replicas, workers, migration jobs, and background services. Close connections promptly and investigate leaked sessions or pools that create more connections than the application can use. Avoid killing sessions indiscriminately because an idle-looking connection may own an open transaction.

Increasing max_connections may require more server resources, and MySQL’s effective maximum can be constrained by open_files_limit. Check the active values and server capacity before changing the global setting; see the max_connections system variable.

MySQL 26.7’s server-side Thread Pool can manage execution threads under high concurrency, but it does not increase max_connections or resolve Error 1040. Consider it only for measured execution-thread contention; for details, see how to enable and measure the MySQL 26.7 Thread Pool.

If the message says a particular user has exceeded max_user_connections, that is a per-account limit (Error 1203), not the global Error 1040; see MySQL Error 1203 troubleshooting and the account resource limit documentation. MySQL X Protocol uses its separate mysqlx_max_connections setting, documented in X Plugin options.

For authentication failures, see MySQL Error 1045. For more connection and SQL errors, browse MySQL Error Troubleshooting.