Loading...

Knowledge Base

How to Fix the MySQL "max_user_connections" Error

What this error means

Every MySQL/MariaDB database user is given a limit on how many connections it can open to the database server at the same time. This limit is called max_user_connections.

When a website, plugin, or script opens more simultaneous database connections than this limit allows, MySQL blocks any new connection and shows an error such as:

User 'db_username' has exceeded the 'max_user_connections' resource (current value: xx) 

This usually means the site is either getting more traffic than the current limit supports, or something on the site (a plugin, a script, a cron job) is opening database connections and not closing them properly, so old connections pile up until the limit is hit.

The fix depends on whether the account is on shared hosting or a VPS, as the level of access varies in each case.

-------------------------------------------------------------------------------------------------------------------------------------------------------

Before you begin: check the current connections

This step is the same on both shared and VPS servers and helps confirm what is actually happening.

Step 1: Log in to phpMyAdmin from cPanel (or via WHM/SSH on a VPS).

Step 2: Click on the SQL tab and run:

SHOW PROCESSLIST;

Step 3: Look at the User column for repeated entries of the affected database user (for example, cpses_at77wkq6im). A large number of rows for the same user, especially many marked Sleep, confirms connections are not being closed properly.

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

Fix on Shared Hosting (Single Domain, Multi Domain, Cloud, and Reseller Linux Hosting) 

On shared servers, max_user_connections is fixed at 150 per database user and cannot be increased, not by the customer and not by support. This limit is set at the server level to keep usage fair across all accounts sharing the same server. If a site is hitting this limit, the fix has to come from reducing the number of connections the site opens at once, not from raising the cap.

Step 1: Identify what is opening the connections

  • If it's a WordPress site, check for plugins related to caching, backups, or database optimisation; these are common causes of excess persistent connections.
  • Check Cron Jobs in cPanel for any scheduled task that queries the database frequently. 

Step 2: Turn off persistent database connections

If the site uses persistent connections (common with some caching plugins or custom scripts), turning this off usually resolves the issue immediately, since each connection is closed as soon as the page finishes loading instead of staying open.

In WordPress, this is normally controlled by a plugin setting or in wp-config.php. Disable any MYSQL_CLIENT_PERSISTENT or persistent-connection setting if present.

Step 3: Reduce concurrent load 

  • Pause or space out any bulk operations (imports, migrations, staging syncs) that open many connections at once. 
  • If a caching plugin is installed but not configured, set it up; this reduces the number of times the page needs to query the database per visit.

Step 4: Optimise the database 

A database with large, unoptimized, or bloated tables makes every query take longer to run. The longer a query takes, the longer that connection stays open; so an unoptimized database fills up the 150-connection limit faster than it should, even at normal traffic.

1. In cPanel, open phpMyAdmin.

2. Select the site's database from the left panel.

3. Click Check All to select every table, then choose Optimise table from the dropdown at the bottom.

This clears overhead built up from regular inserts, updates, and deletes (common on WordPress sites from post revisions, spam comments, and transient options), so queries run faster and connections close sooner.

Step 5: If the error keeps coming back

Since the 150-connection limit cannot be raised on shared hosting, a site that keeps hitting it repeatedly needs a genuine reduction in concurrent database load; through caching, fewer/less frequent cron jobs, or removing a misbehaving plugin. If none of the above steps reduces the connection count, the site's traffic or database usage pattern is likely outgrowing what shared hosting is designed for, and moving to a VPS or a dedicated server (where there is no such cap) is the appropriate next step.

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

Fix on VPS / Dedicated Servers (root access via WHM)

Unlike shared hosting, VPS and Dedicated servers have no fixed cap on max_user_connections. The account holder has root access and can raise the per-user limit or set it to unlimited, since there's no server-wide ceiling imposed on these plans. Both the per-user and server-wide limits are changed manually via SSH/terminal. WHM does not expose these settings in its interface.

NOTE: Before making any changes to /etc/my.cnf, always take a backup first, so it can be restored if something goes wrong:

cp /etc/my.cnf /etc/my.cnf.bak

 

Step 1: Check the server-wide limit via terminal

1. Connect to the server via SSH as root.

2. Open the configuration file:

vi /etc/my.cnf

3. In vi, look for a line with max_connections under the [mysqld] section. This is the total number of connections the whole server allows, across all database users. If the line isn't present, it means the server is using MySQL's default. Press Esc and type :q and press Enter to exit without making changes.

If max_connections is already high and only one database user is hitting its own limit, the fix is to raise that specific user's max_user_connections value (Step 2 below), not the server-wide setting.

Step 2: Raise the per-user connection limit

Still connected via SSH as root, log in to the MySQL command line:

mysql -u root -p

Check the current limit for the affected user:

SELECT User, max_user_connections FROM mysql.user WHERE User = 'db_username';

To raise it (for example, to 50):

UPDATE mysql.user SET max_user_connections = 50 WHERE User='db_username';
FLUSH PRIVILEGES;

Step 3: Raise the server-wide limit if needed 

If several database users are affected, not just one, increase the server-wide limit instead:

1. Back in the terminal (as root), open the configuration file:

vi /etc/my.cnf

2. Under the [mysqld] section, position the cursor where the line should go, press i to enter insert mode, then add or edit the line:

max_connections = 250

Set this to a value appropriate for the server's available RAM (a much higher max_connections on a low-RAM VPS can cause MySQL to run out of memory instead).

3. Press Esc to leave insert mode, then type :wq and press Enter to save and exit. Restart the database service:

systemctl restart mysqld

(Use mariadb in place of mysqld if the server runs MariaDB as the service name)

If MySQL fails to start after the change, restore the backup and restart again:

cp /etc/my.cnf.bak /etc/my.cnf

systemctl restart mysqld

Step 4: Confirm the fix 

Back in the MySQL CLI, run the same check from before:

SHOW PROCESSLIST;

Connections for the affected user should now stay within the new limit, and the site should load without the error.

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

Preventing this in the future

  • Keep caching plugins configured properly; most database connection issues come from a site querying the database far more than necessary.
  • Avoid frequent cron jobs (at intervals under 5 minutes) that hit the database, unless required.
  • On a VPS or dedicated server, monitor SHOW PROCESSLIST periodically if a site has had this issue before, to catch a rising connection count early.
  • Set max_user_connections slightly above the site's typical peak usage, not at the bare minimum, to accommodate normal traffic spikes.

 

Loading...