showing results for - "nodejs mysql connection pool"
Ricardo
02 Feb 2017
1var mysql = require('mysql');
2
3// connect to the db
4dbConnectionInfo = {
5  host: "localhost",
6  port: "3306",
7  user: "root",
8  password: "root",
9  connectionLimit: 5, //mysql connection pool length
10  database: "db_name"
11};
12
13//For mysql single connection
14/* var dbconnection = mysql.createConnection(
15        dbConnectionInfo
16); 
17
18 dbconnection.connect(function (err) {
19    if (!err) {
20        console.log("Database is connected ... nn");
21    } else {
22        console.log("Error connecting database ... nn");
23    }
24}); 
25
26*/
27
28//create mysql connection pool
29var dbconnection = mysql.createPool(
30  dbConnectionInfo
31);
32
33// Attempt to catch disconnects 
34dbconnection.on('connection', function (connection) {
35  console.log('DB Connection established');
36
37  connection.on('error', function (err) {
38    console.error(new Date(), 'MySQL error', err.code);
39  });
40  connection.on('close', function (err) {
41    console.error(new Date(), 'MySQL close', err);
42  });
43
44});
45
46
47module.exports = dbconnection;
48
Alan
29 Jun 2020
1var pool  = mysql.createPool({
2      connectionLimit : 10,
3      host            : 'example.org',
4      user            : 'bobby',
5      password        : 'pass'
6    });
7    
8pool.getConnection(function(err, connection){
9    if(err){
10        return cb(err);
11    }
12    connection.changeUser({database : "firm1"});
13    connection.query("SELECT * from history", function(err, data){
14        connection.release();
15        cb(err, data);
16    });
17});
18
queries leading to this page
pool connection sql nodenodejs have db connection pool import modulecomplate guide connection release 28 29 node jsnodejs mysql connection poolconnection pool node js mysql examplerecommended number for sql pool in api nodemssql node js connection poolmssql connection pool nodejsmysql js poolspool connection mysql node jsnode mysql connection poolingcreate mysql connection pool in node jswhat is connection pool in node jsnodejs mssql connection pool examplemssql pool nodejsmysql connection pool nodejsnode js mssql connection poolhow to end node js script when using mysql connection poolpool on connect in node jsnodejs mysql close poolnode js mssql pool connection examplenode js mysql connection pool examplemysql connection pool express jsmysql pool query nodejsmysql pooling node jsmysql connection pooling node jsnodejs mysql poolconnect pool for mysql in nodejspool mysql node jsmysqljs connection pooldatabase connection pool nodejsnode js mysql create pool executemysql pool nodejsnodejs mysql pool get connection detailnode js mysql connectionpoolmysql connection pooling nodejsmysql pool connection node jsnode js mysql pool examplepool api nodejsmysqlserver pooling in jssql node js where to put connection pool examplenode mysql getconnectionnode js mysql pool querynode js sql poolpool mysql nodejsconnection pooling in node jsexpress js mysql connection poolpool in node jsnodejs mysql pool vs connectionmysql connect pool and questy in nodejsmysql createconnection pool nodejsnodejs mysql connection pool