Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MySQL’s “Too many connections” error (Error 1040) means the server has reached its configured client-connection limit. You can raise that limit with SET GLOBAL max_connections for an immediate change, or use SET PERSIST or server configuration to keep the value after a restart. Before increasing it substantially, check whether connection leaks, oversized pools, idle sessions, or long-running work are consuming slots—and confirm the server has enough resources to support more connections.

What “Too many connections” means

MySQL returns this error when all available client connections are in use. The global max_connections system variable sets the permitted number. MySQL allows one additional connection for an account with CONNECTION_ADMIN (or the deprecated SUPER privilege), so an administrator can connect and inspect the server when ordinary connection slots are exhausted. See Oracle MySQL’s Too many connections documentation.

Diagnose what is using the connections

Before changing the limit, check the configured ceiling, current usage, peak usage, rejected connections, and active sessions:

SHOW GLOBAL VARIABLES LIKE 'max_connections';
SHOW GLOBAL STATUS LIKE 'Threads_connected';
SHOW GLOBAL STATUS LIKE 'Max_used_connections';
SHOW GLOBAL STATUS LIKE 'Connection_errors_max_connections';
SHOW FULL PROCESSLIST;

Threads_connected shows the current number of open connections; Max_used_connections records the highest concurrent count since the server started; and Connection_errors_max_connections counts connections refused because the limit was reached. MySQL documents system-variable inspection and connection monitoring in its system-variable reference and server-status-variable reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In the process list, look for sleeping sessions held by applications, long-running queries or transactions, and sessions that appear to be abandoned. A large number of idle connections may point to oversized application pools or timeout settings; persistent growth may indicate that code is not returning or closing connections. A sudden spike can instead reflect legitimate traffic. For RDS or Aurora MySQL, AWS also documents querying INFORMATION_SCHEMA.PROCESSLIST to inspect connections: Connecting to a DB instance.

Increase max_connections

Change the running server temporarily

To raise the limit until the server restarts, run this as an account with the required administrative privileges:

SET GLOBAL max_connections = 300;

Replace 300 with a value justified by your workload and available resources. The new global value affects new connections; it does not close existing sessions.

Persist the change in MySQL 8.0 and later

On supported MySQL versions and deployments, use SET PERSIST to change the runtime value and save it for subsequent starts:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
SET PERSIST max_connections = 300;

MySQL writes the persisted setting to mysqld-auto.cnf. Syntax, privileges, and support can vary by version and deployment. The MySQL SET statement documentation explains the distinction between SET GLOBAL and SET PERSIST.

Use an option file on a self-managed server

If you manage MySQL through an option file, put the setting in the [mysqld] section and restart the server through your normal operational process:

[mysqld]
max_connections=300

After making a change, confirm the effective setting with SHOW GLOBAL VARIABLES LIKE 'max_connections';. The system-variable reference describes the variable and its configuration behavior.

Choose a safe connection limit

There is no universally safe value. Oracle MySQL’s 2026 reference manual lists a default max_connections of 151 and a maximum of 100,000, but these are documented bounds—not recommended settings for every server. The effective maximum may also be lower because of open_files_limit. Check the current system-variable reference for the version you run.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More connections consume server resources. In MySQL’s one-thread-per-connection model, concurrent clients can add thread and kernel-resource overhead, per-thread memory use, file-descriptor demand, and CPU scheduling work. High connection counts can therefore put pressure on memory and response times even when the configured maximum permits them. See MySQL connection interfaces and MySQL’s thread-pool documentation.

  1. Measure Max_used_connections during representative peak periods rather than sizing from a quiet moment.
  2. Allow a justified margin above observed peaks, taking expected traffic growth into account.
  3. Assess whether the server can handle the additional concurrent connections under worst-case memory and workload conditions.
  4. After changing the limit, monitor connection use and server behavior, and alert before usage approaches the ceiling.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fix the cause when possible

Raising the limit can relieve a genuine concurrency bottleneck, but it will not correct a leak or an application that keeps too many idle connections open. Match the remedy to what the process list and connection metrics show:

  • Abandoned or leaked sessions: correct application cleanup so every code path returns connections to its pool or closes them.
  • Too many idle pooled connections: reduce pool sizes and tune client-side idle and connection-lifetime limits to fit the workload.
  • Long-running work: investigate queries and transactions that hold connections longer than needed.
  • Legitimate high concurrency: consider a connection pooler or, where available, MySQL’s Enterprise thread pool to reduce overhead at high client counts.

MySQL describes the resource trade-offs of its connection model and the Enterprise thread pool in its thread-pool documentation. AWS also recommends inspecting and tuning connections rather than blindly raising the limit in its RDS connection guidance.

Recover access when ordinary connection slots are full

Keep a dedicated administrative account with CONNECTION_ADMIN (or the version-appropriate privilege) so you can use the reserved administrative connection. Once connected, run SHOW FULL PROCESSLIST; to identify sessions consuming slots. Terminate only sessions you have confirmed are safe to stop; killing an active session can interrupt work or roll back a transaction. Do not grant broad administrative privileges to ordinary application accounts. MySQL documents the reserved slot and privilege in its connection-limit guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which remedy fits your situation?

Remedy When it fits How long it lasts Main trade-off
SET GLOBAL max_connections A temporary increase is needed while you investigate or handle a short-lived demand spike. Until restart. More connections can consume additional memory, threads, file descriptors, and CPU scheduling capacity.
SET PERSIST or option-file configuration The higher ceiling is justified beyond the current server session. Survives restart when supported and configured. A persistent increase can preserve an unsafe setting; validate capacity and monitor after the change.
Pool, application, or query changes Leaks, oversized idle pools, or long-running sessions are driving connection use. Addresses the underlying behavior. Requires application or workload changes rather than only a server setting.
Pooler or thread-pool approach The workload genuinely needs high concurrency and connection overhead is a concern. Architectural change. Requires compatibility and operational evaluation; MySQL Enterprise thread-pool availability depends on the deployment.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.