Connection Limits
What a Database Connection Is
Max connections MySQL is the server setting that caps how many client sessions the server will accept at the same time. A database connection is an open session between an application and the database server. Before a query can run, the application opens a connection, authenticates, sends its SQL and reads the results. Each open connection uses memory and server resources, which is why servers limit how many they hold.
On a website, connections are often opened by PHP or another web process on each page request. When many visitors arrive at once, many requests need connections at the same moment.
Why the Too Many Connections Error Appears
When every connection slot is in use, the next client is refused with an error such as “Too many connections”. The visitor usually sees a blank page or a database error. The limit is not always too low. Often the real cause is that connections stay open for too long.
Common reasons include slow queries that hold a connection while they run, traffic spikes, scripts that open connections and never release them, and web servers configured with more worker processes than the database can support. Shared hosting plans may also set a per-account limit, so a single busy site can exhaust its own allowance as described in database user privileges.
Connection Pooling and Other Fixes
Connection pooling keeps a fixed set of open connections and lends them to requests as needed, instead of opening and closing a new one each time. This reduces overhead and keeps the number of connections under control. Pooling is provided by some application servers, middleware and database proxies.
Other fixes address the cause rather than the symptom. Improving slow queries shortens how long each connection is busy. Caching reduces how often the database is queried at all. Some sites do need more capacity, but that should follow an investigation of the actual bottleneck.
A News Site Under a Sudden Spike
A news site on a shared plan receives a sudden surge of visitors after a story spreads widely. Each page request runs a query that takes several seconds, so connections pile up. Pages start failing with “Too many connections”, even though the traffic was not extreme for the site. Speeding up the query freed connections faster than new requests could fill them.
Frequently asked questions
Is raising the max connections a good fix?
Sometimes, but it often hides the real problem. Each connection uses memory, so a higher limit can push the server into memory pressure and make everything slower. It is better to find out why connections stay open first, then decide whether more capacity is genuinely needed.
Why does my site show too many connections only at peak times?
Peak traffic means more requests need a connection at the same moment, so the limit is reached sooner. Slow queries make this worse, because each connection stays busy longer. Looking at how long requests take during peaks, and how many connections are open, usually shows whether the cause is volume or slowness.