Skip to content

Instantly share code, notes, and snippets.

@Slurpgoose
Slurpgoose / mysqlConnector.js
Last active January 3, 2023 19:25
A method to wrap your node application with a mysql pool.
/*
Created with refrence from
https://gist.github.com/binki/52662f18ae6fc89b18b020b89aa4e1cd
http://www.madhur.co.in/blog/2016/09/05/nodejs-connection-pooling.html
*/
const mysql = require('mysql'); // import
const pool = mysql.createPool({ // create pool instance
host: "*",
user: "*",
@binki
binki / README.md
Created January 16, 2019 17:10
mysql connection pooling in node.js

This is in reaction to http://www.madhur.co.in/blog/2016/09/05/nodejs-connection-pooling.html

It is critical that you remember to release connections to the pool if you are using pooling with the mysql module. It is best to use the pool.query() command if you can. You’ll know if you can’t.

Examples of things which cannot use pool.query() but must use pool.getConnection() followed by connection.release() are:

  1. Using transactions where you send multiple commands to the server.
  2. Sharing per-session data objects between subsequent commands sent to the server such as temporary tables.