Menu

"Too many connections" in MySQL: connection pools done right in Node.js
📰

"Too many connections" in MySQL: connection pools done right in Node.js

DEV Community: mysql·Ahmed Adil Abuzaid·1 day ago
#ipzJb8DS
#devtomysql#devto#dev#pool#connections
Long article (1603 words) — no AI summary yet.
Reading 0:00
15s threshold

Your Node.js app runs fine for days. Then a busy hour arrives, like an event registration opening or a newsletter going out, and the logs fill with Error: Too many connections . The MySQL too many connections error is rarely a database problem. It is almost always the app opening connections faster than it gives them back.

This bug-log entry covers why it happens, the pattern I use in every Node.js project now, and how to watch connections live so you know the fix worked.

Why MySQL says "too many connections"

MySQL has a hard ceiling, max_connections . The default on a fresh install is usually 151, but check your own server. When every slot is taken, new clients get refused, and your API returns 500s even though the database is not busy at all.

In Node.js projects, three causes cover nearly every case I have seen:

A new connection per request. The handler calls createConnection() , runs a query and moves on. Under light traffic you never notice. Under load you open hundreds.

Leaks.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.