Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article3 min readViews0

Too Many MySQL Connections: Which Metrics to Check First

Compare current connections, active threads, and the server limit to identify the cause of failures before increasing the connection limit.

Patch panel with numerous network connections
In this article

The error about exceeding the number of connections often triggers a simplistic solution: increase the limit. However, each connection consumes resources, and the cause may lie in hung queries or an incorrect application pool. First, you must determine how many connections are open and what work they are performing.

Capture metrics in a single context

The SQL examples are for MySQL 8.x and run in an already open session with permissions to view the necessary variables. They do not change data or settings. If access is restricted, request these metrics from the administrator without automatically expanding the application account's permissions.

SHOW GLOBAL STATUS LIKE 'Threads_connected';

SHOW GLOBAL STATUS LIKE 'Threads_running';

SHOW GLOBAL VARIABLES LIKE 'max_connections';

The first metric refers to currently open connections. The second helps evaluate threads that are not sleeping. The limit setting shows the allowed boundary for standard connections. These are different values, and they must be compared with consideration for the measurement time.

Look for accumulated signs

Two more queries are useful:

SHOW GLOBAL STATUS LIKE 'Max_used_connections';

SHOW GLOBAL STATUS LIKE 'Connection_errors_max_connections';

Peak connection counts and failure counters help determine if the issue occurred previously. However, accumulated values do not describe the current second. Consider server restarts and statistics resets if they occurred between the measurements being compared.

Distinguish between open connections and productive work

A large pool can hold many waiting connections. In another scenario, there are few connections, but each request takes a long time to execute. Increasing the limit in the second case may intensify competition for CPU and disk without resolving the bottleneck.

Example: after deploying the application, the number of instances increased, but the pool size in each remained the same. The total potential demand now exceeds the server limit. Here, calculations must account for all applications, background tasks, and administrative connections, not just a single container configuration.

When a process list is needed

For further analysis, an administrator can view current connections and queries. Such output may contain SQL with customer data. It should not be published in full in a general chat; typically, duration, status, source application, and an anonymized example are sufficient.

Do not terminate all waiting connections en masse. Some belong to the standard pool, while others perform significant operations. If intervention is required, it must be tied to a specific owner and scenario.

How to Verify the Solution

Correlate the moment of failure with traffic spikes, deployments, or import launches. Then evaluate request duration and pool settings. Adjusting the limit must be considered alongside server resources and expected contention.

After applying the fix, repeat measurements during comparable load and check if the failure counter is increasing. Save both the initial and final states. A stable result means no failures within acceptable request times and a clear number of connections, not merely a higher limit in the configuration.

Discussion0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.