DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk9 min

How to Change MySQL max_connections on Ubuntu (Safely)

A practical Ubuntu guide to changing MySQL max_connections persistently or at runtime, with verification queries, capacity checks, systemd limits, emergency access and rollback steps.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On an Ubuntu installation, the normal persistent setting is in /etc/mysql/mysql.conf.d/mysqld.cnf under [mysqld]. Add or edit max_connections, then restart mysql.service. For an immediate change without restarting, an authorized MySQL account can use SET GLOBAL; use SET PERSIST when you want MySQL to apply the change now and retain it across restarts. Choose the value from measured concurrent demand and the server’s memory and file-descriptor capacity, not from a generic number.

Choose the change method first

There are three supported ways to change the global max_connections value. They differ in interruption, persistence, privilege requirements and how easily an operations team can audit the change.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Method Applies immediately Survives a restart Operational effect Where the setting is recorded Best use
SET GLOBAL max_connections = n Yes No, unless another persistent source already sets the same value No MySQL service restart Running server memory Fast testing or emergency relief
SET PERSIST max_connections = n Yes Yes No service restart MySQL’s mysqld-auto.cnf Live change that MySQL itself should retain
Option-file edit After restart Yes Requires restarting mysql.service Ubuntu configuration, normally /etc/mysql/mysql.conf.d/mysqld.cnf Configuration-managed, reviewable server setup

Use one persistence approach deliberately. Combining an option-file value with a value in mysqld-auto.cnf can make later troubleshooting and configuration audits harder because the same variable is being maintained in two places.

Measure whether a higher limit is actually needed

Increasing the ceiling does not create database capacity. It allows more client sessions to exist, and each additional session can consume memory, file descriptors and CPU time. A connection refusal can be caused by a burst, an oversized connection pool, slow queries that keep sessions occupied, or an application that fails to release connections. Raise the limit only after identifying which of those conditions is present.

Capture the current limit and usage

Connect to MySQL and run:

SHOW GLOBAL VARIABLES LIKE 'max_connections';
SHOW GLOBAL STATUS LIKE 'Threads_connected';
SHOW GLOBAL STATUS LIKE 'Threads_running';
SHOW GLOBAL STATUS LIKE 'Connection_errors_max_connections';
  • max_connections is the configured global ceiling.
  • Threads_connected is the number of currently open client connections, including idle sessions.
  • Threads_running shows sessions actively executing rather than merely connected; a much lower value than Threads_connected can point to idle pooling or leaked connections.
  • Connection_errors_max_connections counts refusals that occurred because the connection limit was reached. MySQL increments this status counter when that condition happens.

Sample these values during the busiest normal period and during the incident that prompted the change. A single quiet-time reading can hide a short peak. Compare the peak Threads_connected with the configured ceiling, then inspect application pool limits and connection lifetimes before choosing a new number.

Separate demand from a pooling problem

If the application opens hundreds of idle sessions but runs only a few queries at a time, raising max_connections may only defer the same failure while increasing memory pressure. Check whether pools have an unnecessarily high maximum, whether abandoned sessions are being closed, and whether a connection is held while waiting on slow work outside the database. Fixing those behaviors can reduce the required ceiling without changing MySQL.

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

Set max_connections persistently in Ubuntu’s option file

Ubuntu’s packaged MySQL layout commonly uses /etc/mysql/mysql.conf.d/mysqld.cnf. Put the variable in the [mysqld] server section, not in a client section.

1. Back up the file and open it as root

sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.backup
sudoedit /etc/mysql/mysql.conf.d/mysqld.cnf

The backup gives you a direct rollback copy if the edit is mistyped or the service does not start afterward. If the file already has a [mysqld] section, edit the existing max_connections line rather than creating a second line for the same variable.

2. Add or change the server setting

Inside the [mysqld] section, use an integer value appropriate for your measured peak:

[mysqld]
max_connections = 300

The example value of 300 is an illustration, not a recommendation for every Ubuntu host. Keep the section header exactly as shown and avoid placing the line below a different section header. Save the file with root ownership and normal configuration-file permissions.

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

3. Restart the Debian-family service

sudo systemctl restart mysql.service
sudo systemctl status mysql.service

Ubuntu uses the mysql systemd service name. The restart is the point at which the option-file value is read, so an edit alone does not change the running server.

4. Verify the effective value

mysql -u your_admin_user -p -e "SHOW GLOBAL VARIABLES LIKE 'max_connections';"

Replace your_admin_user with an account permitted to inspect global variables. Confirm that the returned value matches the file and that the service status is active. If the service fails to start, restore the backup, restart again, and then review the edited section for a spelling, syntax or placement error.

Change the running server with SET GLOBAL

max_connections is a global, dynamic integer variable. MySQL permits dynamic variables to be changed while the server is running with SET. This method is useful when you need an immediate test or short-term relief and cannot interrupt client traffic.

Run the change

SET GLOBAL max_connections = 300;
SHOW GLOBAL VARIABLES LIKE 'max_connections';

Run these statements in a session authenticated as an account authorized to change global variables. The second statement confirms the live value. Existing client sessions are not disconnected merely because the ceiling changes; the new limit applies when MySQL evaluates subsequent connection attempts.

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

Understand its persistence boundary

SET GLOBAL changes the running server but is not, by itself, a durable Ubuntu option-file configuration. After a service restart, the value can return to whatever persistent configuration MySQL reads. Record the temporary change in your incident or change log, and either revert it deliberately or convert it to one persistent method after measuring the result.

Use SET PERSIST for an immediate, restart-safe SQL change

SET PERSIST is the middle option: it changes the live value and writes a persisted setting that MySQL will use after a restart. Current MySQL 8.0 documentation shows this form:

SET PERSIST max_connections = 300;
SHOW GLOBAL VARIABLES LIKE 'max_connections';

The statement requires an account with the necessary administrative privilege. It writes the persisted value to MySQL’s mysqld-auto.cnf, so no Ubuntu service restart is needed for the first application of the change. Verify the live result with SHOW GLOBAL VARIABLES, then include the persisted-file change in your configuration records.

Choose SET PERSIST when MySQL-managed persistence is intentional. Choose the Ubuntu option file when your team expects server settings to live in a reviewed, configuration-managed file. Do not maintain an untracked value in both locations without documenting which process owns it.

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

Check memory, workload and file-descriptor headroom

MySQL’s practical connection limit depends on available RAM, memory used per connection, workload, desired response time and available file descriptors. The server does not reserve one identical, fixed amount of memory for every connection: buffers, temporary work and query patterns affect the total. A value that works on one machine can exhaust another machine with less RAM or a different workload.

Use a capacity calculation based on observations

  • Start with the highest observed Threads_connected during a representative peak, not the current value at an idle moment.
  • Account for legitimate growth and short bursts, while leaving RAM for the operating system, the InnoDB buffer pool and other MySQL allocations.
  • Check whether connection pools can create the proposed number of sessions simultaneously; the application may reach the limit faster than request volume suggests.
  • After changing the value, watch memory consumption, swap activity, query latency, Threads_running and Connection_errors_max_connections.

MySQL’s current 8.0 reference documentation gives a broad capability statement that Linux or Solaris should support at least 500 to 1,000 simultaneous connections routinely, and as many as 10,000 under high-memory, low-per-connection-demand conditions. Those figures describe general platform capability, not a tuning target for a particular Ubuntu server. Treat your host’s measured memory and workload as the deciding evidence.

Account for open-file limits

MySQL explicitly notes that increasing max_connections increases the number of file descriptors that mysqld requires. If the new value is reasonable for RAM but connections still fail, inspect the systemd service’s LimitNOFILE setting and related open-file limits. A service-level descriptor ceiling can prevent MySQL from using the configured connection ceiling.

Check the service definition and its effective limits through your normal systemd administration process. Raise a descriptor limit only after confirming that the workload needs it and that the operating system can safely support the resulting number of open files. A larger descriptor allowance does not compensate for insufficient memory or an unhealthy connection pool.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use the reserved administrative connection during saturation

MySQL permits max_connections + 1 client connections. The extra slot is reserved for an account with the CONNECTION_ADMIN privilege (or the deprecated SUPER privilege), allowing an administrator to connect and inspect a saturated server.

Keep a tested administrative account with the appropriate privilege and credentials available before an outage. Use that reserved session for diagnosis: inspect the four variables and status counters above, identify the application or pool consuming sessions, and apply a measured fix. Do not give broad administrative privileges to ordinary application accounts solely to make the emergency slot available.

Troubleshoot common failure modes

The value changes, then returns after a restart

This is expected for SET GLOBAL when no persistent configuration was changed. Use the Ubuntu option file or SET PERSIST, then verify the value after a controlled restart. If both persistence mechanisms are in use, establish one owner for the setting and remove the unneeded duplicate.

SET GLOBAL or SET PERSIST returns an access error

The account lacks the privilege required to change a global variable. Reconnect with an authorized administrative account. If you cannot obtain one, use your organization’s approved privilege-escalation process rather than granting permanent high-level rights to an application user.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Connections are refused even though max_connections is high

  • Check Connection_errors_max_connections to confirm that the refusal is specifically due to the MySQL connection ceiling.
  • Check Threads_connected and Threads_running together; many connected but idle sessions suggest pooling or cleanup issues, while many running sessions suggest workload or query-concurrency pressure.
  • Inspect available RAM and swap behavior. A high ceiling that allows excessive per-connection allocation can make the server slower or unstable.
  • Inspect systemd LimitNOFILE and related open-file limits because the service may be unable to obtain enough descriptors.
  • Confirm that the application is connecting to the expected MySQL instance and that its own pool maximum is not lower than the intended capacity.

The service does not start after editing mysqld.cnf

Restore the backup, run sudo systemctl restart mysql.service, and confirm the service status. Then re-open the file and check that max_connections is inside [mysqld], uses an integer, and is not duplicated with conflicting edits. Make one correction at a time so the failing change remains identifiable.

The server becomes slower after raising the limit

Lower the value to the last known-safe setting, reduce application pool sizes or fix leaked sessions, and investigate query concurrency. A successful restart or a higher reported limit is not proof that the host can serve that many simultaneous workloads at the desired response time.

Rollback and document the change

Rolling back a runtime-only change

If you used SET GLOBAL, set the previous value again:

SET GLOBAL max_connections = previous_value;

Replace previous_value with the value you recorded before changing it. This rollback lasts until the next restart unless a persistent source specifies another value.

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

Rolling back SET PERSIST

Use MySQL’s documented persistence-management procedure for your server version to remove or replace the persisted value, then confirm the live setting with SHOW GLOBAL VARIABLES LIKE 'max_connections';. Keep the rollback under the same change-control process as the original edit so the SQL-managed file is not silently overwritten by a later configuration deployment.

Rolling back the Ubuntu option-file edit

Restore /etc/mysql/mysql.conf.d/mysqld.cnf.backup (or edit the line back to its recorded value), then restart mysql.service and verify both service status and the effective variable. Record the old and new values, the peak Threads_connected that justified the change, observed memory and descriptor headroom, and the owner of the persistent configuration.

A practical operating checklist

  1. Measure max_connections, Threads_connected, Threads_running and Connection_errors_max_connections during the real peak.
  2. Determine whether the cause is demand, an oversized or leaking pool, slow work, memory pressure or file-descriptor limits.
  3. Select the method: SET GLOBAL for a temporary live test, SET PERSIST for MySQL-managed persistence, or mysqld.cnf for an Ubuntu configuration-file change.
  4. Set a value supported by measured RAM, per-connection demand, workload and open-file limits.
  5. Verify the effective variable and monitor connection errors, memory, latency and running threads after the change.
  6. Document the owner and rollback path, and remove any duplicate persistence source that could make the next restart surprising.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.