Skip to content
A node.js mysql adapter for managing/querying pooled connections on top of "node-mysql" module.
JavaScript CoffeeScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


npm install mysql-connection-pool


A Node.js api wrapper for a cluster of MySQL instances. Probably a naive approach but could become more fully-featured and tested in the future. Would only recommend as experimental. Uses node-mysql and underscore modules.

Here's an example using it:

// Load module
var MysqlConnectionPool = require('mysql-connection-pool');

// List of all host configurations
var configurations = [
    {host:'', user:'user', password:'secret', database:'dbname'},
    {host:'', user:'user', password:'secret', database:'dbname'},
    {host:'', user:'user', password:'secret', database:'dbname'}

// Initialize pool of connections
var pool = new MysqlConnectionPool(configurations);

// Opens all connections in the pool;

// Query a connection in the pool, logging output
pool.query('show tables;', function(err, rows){
    if (err){ throw err; }

// Close the entire pool after 3 seconds (otherwise thread remains open)
setTimeout(function(){pool.close();}, 3000);

Using an external config:

var _ = require('underscore');
var config = require('./config');
var MysqlConnectionPool = require('mysql-connection-pool');

var pool = new MysqlConnectionPool(, function(host){
    return {
        host     : host,
        user     : config.user,
        password : config.password,
        database : config.database
Something went wrong with that request. Please try again.