Error 1040 · database

MySQL: Too many connections

In one line

Your account is already holding as many database connections as it's allowed, so new requests are refused until one frees up.

Ben Johnson · last verified 2026-08-04

Also seen as: ERROR 1040 · User already has more than max_user_connections · database connection limit

What it actually means

Shared hosting caps how many database connections one account may hold at the same time — often around five on a free plan. When every slot is occupied, the next connection attempt is refused.

The important characteristic is that this error is intermittent. The site works, then doesn’t, then does again. That flickering is the tell that distinguishes it from wrong credentials, which fail every single time.

On WordPress the underlying error is usually hidden behind the generic error establishing a database connection message. Same cause, less useful wording.

Connections free up when a script finishes. So this is really a symptom of scripts taking too long, or not closing what they open.

Diagram illustrating database errors on shared web hosting.

Why it happens

Pages are slow, so connections stay open longer

A connection is held for the whole life of a request. If pages take two seconds instead of two hundred milliseconds, each connection is held ten times as long, and you run out at a tenth of the traffic.

This makes connection limits and 508 errors two symptoms of the same underlying problem.

Code opening a second connection per page

A plugin or library that creates its own connection rather than reusing the application’s. Two connections per visitor halves your effective capacity.

Persistent connections

mysqli_pconnect() or PDO’s ATTR_PERSISTENT keeps a connection open after the script ends, hoping to reuse it. On shared hosting this is usually a mistake — the connections accumulate and sit idle in your quota.

A long-running script holding a connection

An import or report that runs for minutes holds its connection for the duration, leaving fewer for everyone visiting the site.

How to fix it

1. Look at what's actually connected

In phpMyAdmin, run:

SHOW PROCESSLIST;

The Command and Time columns are what matter. Anything sitting in Sleep for a long time is a connection something opened and never closed. Several of those means a code problem, not a traffic problem.

A query stuck in Sending data for many seconds is a slow query — that’s your real cause.

2. Turn on caching

The highest-leverage fix, and the same one as for most shared hosting limits. A cached page never runs PHP, so it never opens a database connection at all.

On a typical WordPress site this cuts database connections by roughly 90%, which usually ends the problem outright without touching any code.

3. Fix the slow queries

Shorter queries mean connections are held for less time, which raises how much traffic the same limit supports.

EXPLAIN SELECT * FROM orders WHERE customer_email = '[email protected]';

If type is ALL, it’s scanning the whole table. An index turns a two-second query into a few milliseconds, and frees the connection ten times sooner.

4. Stop using persistent connections

// Wrong on shared hosting
$db = new PDO($dsn, $user, $pass, [PDO::ATTR_PERSISTENT => true]);

// Right
$db = new PDO($dsn, $user, $pass);

Persistent connections are for environments where you control the pool. On shared hosting they just occupy your quota while idle.

5. Close connections in long scripts

For anything long-running, connect late and close early:

$data = fetch_everything_needed();   // connection open
$db->close();                        // release it
process_slowly($data);               // no connection held

Don’t hold a connection while doing work that doesn’t need one.

On CWP specifically

Our platform

Free CWP accounts allow 5 concurrent MySQL connections. That’s comfortable for a cached WordPress site and tight for an uncached one — which is why caching is the first thing we suggest rather than an upgrade.

Because our databases run on separate servers from web nodes, your DB_HOST is never localhost. The correct hostname is on the MySQL Databases page of your control panel.

When this means you've outgrown free hosting

Be honest with yourself

Persistent connection exhaustion on a properly cached site with indexed queries means genuine concurrent traffic, and that needs a plan with a higher connection limit.

Check the two free fixes first though. An uncached WordPress site can exhaust five connections at surprisingly modest traffic, and caching costs nothing.

Still stuck?

Post the exact error and your account name on the community forum — staff and other users answer there, and the thread helps the next person who hits this.