npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mysql-pool-03

v0.2.5

Published

MySQL connection pool for node.js on top of node-mysql.

Readme

node-mysql-pool is a MySQL connection pool for node.js on top of Felix Geisendörfer's MySQL client node-mysql.

Using a connection pool instead of a single connection should render a remarkable speed-up, when you have many short living connections, e.g. with message board applications.

var MySQLPool = require("mysql-pool").MySQLPool;
var pool = new MySQLPool({
  poolSize: 4,
  user:     'root',
  password: 'root',
  database: 'test'
});

pool.query("SELECT 'Hello, World!' AS hello", function(err, rows, fields) {
  if(err) throw err;
  console.log(rows[0].hello);
});

for(var i = 0; i < 10; ++i) {
  pool.query("SELECT SLEEP(2), ? AS i", [i], function(err, rows, fields) {
    if(err) throw err;
    console.log("Slept: " + rows[0].i);
  });
}

You probably do not have to change anything if you already used node-mysql or any of its forks!

This module is currently not backed by proper unit testing. Nevertheless I found it stable for my testings.

If you find an error, please file an issue!

This module was only tested using node >= 0.4.x. It does not work with older versions of node.js.

The node-mysql-pool even works with unknown forks of node-mysql, as long as

  • the last parameter of any method is the callback function,
  • no events at all are emitted when supplying a callback function, and
  • when the first parameter of a callback is set, it denotes an error.

Otherwise the requirements are the same as for node-mysql.

  • Using npm: npm install mysql-pool
  • Using git:

The API of this module is as similar to node-mysql as possible, with two exceptions:

  • You must always supply a callback function. Using listeners is not supported.
  • Property x, when not supplied while creation, are to be set to instance.properties.x.

When called back, this will be the used connection. (You probably never need to know which connection was actually used.)

mysqlPool.Pool([options])

creates a new, currently empty. Any property for the single connections or the connectionpool, resp., can be set using the options object.

If the parameter poolsize is omitted, 1 is used.

Only if all connection attemps failed err is supplied. If some connections failed, result.error will contain a list of Errors. If some or all connections succeeded, results.connections will contains the pool's size.

Defaults:

pool.poolSize = 1
pool.mysql = require("mysql")
  • pool.poolSize:
    • The number of connections to establish to the server.
  • pool.mysql:
    • If you do not want the npm version of node-mysql—e.g. because you forked and tweaked it for your purposes—you can supply a different library to use.
  • pool.properties.xyz = undefined:
    • Property xyz of the mysql.Client object. See the original documentation of node-mysql for more property related information.

client.useDatabase(database, cb)
client.end([cb])
client.destroy()
  • pool.useDatabase(database, cb):
    • Changes the database for every connection.
  • pool.end([cb]):
    • Shuts down every connection, not waiting for any enqueued and waiting queries. Active queries won't be aborted, though.
  • pool.destroy():
    • Kills every connection. You do not want do use this method!

For all methods you can invoke on a single connection, there is an equivalent methodnameAll(...) method. E.g. you can use pool.pingAll(cb), if you want you to ping all connections for some reason.

cb will be called once for every connection affected. Subject to change!

All methods of the Client object will be supported—with connect(...), end(...), useDatabase(...) and destroy(...) being overwritten.

If you do not use a fork, that are currently:

query(sql, [params], cb)
ping([cb]))
statistics([cb])

See the original documentation of node-mysql for method related information.

Beware:

  • You must supply a callback method, if you have any parameters.
  • No events are emitted but error.

format(sql, params)
escape(val)

Will behave exactly like the original methods. They do not belong to a single connection.

Emitted if and only if an error occurred and no callback function was supplied. You should always supply a callback function!

  • The methods affecting all connections have a strange API. cb should be called only once.

node-mysql-pool is licensed under the MIT license.