Too many connections with connection pool
See original GitHub issueI’m getting too many connections error when I make exactly 30 insert queries on my node app.
I have a connect.js file like this:
async function connection() {
try {
const mysql = require('mysql2');
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DATABASE,
connectionLimit: 10,
waitForConnections: true,
queueLimit: 0
});
const promisePool = pool.promise();
return promisePool;
} catch (error) {
return console.log(`Could not connect - ${error}`);
}
}
module.exports = {
connection
};
and another file that I import the connect.js
like this:
let connection = require('connect');
let db = await connection();
then sql queries with db.execute();
follows.
Please help. Thanks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (1 by maintainers)
Top Results From Across the Web
MySQL Error: Too many connections - Percona
Most of the time, an overly high number of connections is the result of either bugs in applications not closing connections properly or...
Read more >Resolve "Too Many Connections" error when ... - AWS
Review existing connections and, if possible, terminate them to release connection pressure. For example, start by terminating connections in ...
Read more >MySQL Error “Too many connections” and how to resolve it
When a client tries to log into MySQL it may sometimes be rejected and receive an error message saying that there are “too...
Read more >MySQL 8.0 Reference Manual :: B.3.2.5 Too many connections
If clients encounter Too many connections errors when attempting to connect to the mysqld server, all available connections are in use by other...
Read more >Solve MySQL/MariaDB "Too many connections" error - IONOS
The MySQL “Too many connections” error occurs when more queries are sent to a MySQL database than can be processed. The error can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
you are creating new pool each time instead of borrowing connection from the same pool. Change to something like this:
In another file
const db = require('path to file');
Then to run a query
const [query] = await db.execute(/*query here*/);