Fixing the "Too Many Connections" Database Error

Category: Databases ยท Updated 2026-11-06

"Too many connections" means a database server, usually MySQL or MariaDB, has reached its max_connections limit and is refusing new client connections until one closes. It is most often caused by a traffic spike, a plugin or script that opens connections without closing them, or a limit set too low for the site's actual load. The fix is to close or reduce unneeded connections and, if the server has capacity, raise max_connections.

What the error means

Every application that talks to a database, for example PHP through WordPress, opens a connection to it. The database server has a configured ceiling on how many of these connections can be open at once, controlled in MySQL and MariaDB by the max_connections setting. When that ceiling is reached, the next attempt is rejected with an error such as:

ERROR 1040 (08004): Too many connections

This is a server-side limit being hit, not necessarily a sign that the database itself crashed or that data was lost.

Common causes

  • Traffic spike: more simultaneous visitors than usual, each needing a connection at the same moment.
  • Connections not closed: buggy code or a plugin that opens a connection and never releases it, slowly eating up the pool.
  • Too many PHP-FPM or application workers: each one can open its own connection, so raising worker counts without raising max_connections creates a mismatch.
  • A low default limit: some hosting plans or default installs set max_connections conservatively, well below what a busy site needs.
  • Slow queries: a query that takes a long time to finish holds its connection open longer, so slow queries pile up and exhaust the limit faster than they would otherwise.

How to fix it

  1. Check the current limit and usage:
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected';
SHOW PROCESSLIST;
  1. Look for stuck or idle connections in the process list and find the script or plugin opening them.
  2. Raise the limit if the server has RAM to spare, either temporarily or permanently:
-- Temporary, until the next restart
SET GLOBAL max_connections = 200;

-- Permanent, in my.cnf under [mysqld]
max_connections = 200
  1. Restart the database service after editing the configuration file so the new value takes effect.

Raising max_connections without enough RAM can cause the database to run out of memory under load instead, so increase it in modest steps and watch server memory usage.

Preventing it long term

  • Use a connection pool or persistent connections carefully, so connections are reused instead of opened fresh for every request.
  • Add caching (object cache or full-page cache) so fewer requests need to reach the database at all.
  • Fix or disable plugins that leak connections, and optimize slow queries so they release connections faster.
  • Monitor Threads_connected over time so you can raise the limit, or your hosting plan, before the error happens during a real traffic spike.

Frequently asked questions

What does "too many connections" mean in MySQL?

It means the database server already has as many open connections as its max_connections setting allows, so it is rejecting new ones until an existing connection closes.

How do I fix the too many connections error?

Close or identify what is holding connections open using SHOW PROCESSLIST, fix any script or plugin that leaks connections, and raise max_connections if the server has enough RAM to support more.

How do I increase max_connections in MySQL?

Run SET GLOBAL max_connections = <number> for an immediate but temporary change, or add max_connections = <number> under the [mysqld] section of my.cnf and restart MySQL for a permanent change.

Can too many connections crash my whole site?

It can make the site unusable temporarily, since pages that need the database will fail to load, but it does not normally corrupt data. Once connections free up or the limit is raised, normal service resumes.

What is the default max_connections value?

Many MySQL and MariaDB installs default to around 151 connections, though hosting providers often set a different value based on the server's available memory. Check with SHOW VARIABLES LIKE 'max_connections' rather than assuming.

Why do I get this error even with low traffic?

A low max_connections setting, a plugin that opens connections without closing them, or a small number of slow queries holding connections open can all trigger the error even on a site with modest traffic.

Is this a hosting plan limit or a MySQL setting?

It can be either. Shared hosting plans sometimes cap connections per account regardless of the MySQL-wide setting, while on a VPS or dedicated server you control max_connections directly in the database configuration.

Related topics