function createConnection(config) { var Connection = loadClass('Connection'); var ConnectionConfig = loadClass('ConnectionConfig'); return new Connection({config: new ConnectionConfig(config)}); }
...
The first thing you will run into is that the old `Client` class is gone and
has been replaced with a less ambitious `Connection` class. So instead of
`mysql.createClient()`, you now have to:
```js
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
});
connection.query('SELECT 1', function(err, rows) {
if (err) throw err;
...
function createPool(config) { var Pool = loadClass('Pool'); var PoolConfig = loadClass('PoolConfig'); return new Pool({config: new PoolConfig(config)}); }
...
```
Unlike `end()` the `destroy()` method does not take a callback argument.
## Pooling connections
Rather than creating and managing connections one-by-one, this module also
provides built-in connection pooling using `mysql.createPool(config)`.
[Read more about connection pooling](https://en.wikipedia.org/wiki/Connection_pool).
Create a pool and use it directly:
```js
var mysql = require('mysql');
var pool = mysql.createPool({
...
function createPoolCluster(config) { var PoolCluster = loadClass('PoolCluster'); return new PoolCluster(config); }
...
## PoolCluster
PoolCluster provides multiple hosts connection. (group & retry & selector)
```js
// create
var poolCluster = mysql.createPoolCluster();
// add configurations (the config is a pool config object)
poolCluster.add(config); // add configuration with automatic name
poolCluster.add('MASTER', masterConfig); // add a named configuration
poolCluster.add('SLAVE1', slave1Config);
poolCluster.add('SLAVE2', slave2Config);
...
function createQuery(sql, values, callback) { var Connection = loadClass('Connection'); return Connection.createQuery(sql, values, callback); }
...
* @param {function} [callback] The callback to use when query is complete
* @return {Query} New query object
* @public
*/
exports.createQuery = function createQuery(sql, values, callback) {
var Connection = loadClass('Connection');
return Connection.createQuery(sql, values, callback);
};
/**
* Escape a value for SQL.
* @param {*} value The value to escape
* @param {boolean} [stringifyObjects=false] Setting if objects should be stringified
* @param {string} [timeZone=local] Setting for time zone to use for Date conversion
...
function escape(value, stringifyObjects, timeZone) { var SqlString = loadClass('SqlString'); return SqlString.escape(value, stringifyObjects, timeZone); }
...
## v2.0.0-alpha5 (2012-12-03)
* Add mysql.escapeId to escape identifiers (closes #342)
* Allow custom escaping mode (config.queryFormat)
* Convert DATE columns to configured timezone instead of UTC (#332)
* Convert LONGLONG and NEWDECIMAL to numbers (#333)
* Fix Connection.escape() (fixes #330)
* Changed Readme ambiguity about custom type cast fallback
* Change typeCast to receive Connection instead of Connection.config.timezone
* Fix drain event having useless err parameter
* Add Connection.statistics() back from v0.9
* Add Connection.ping() back from v0.9
## v2.0.0-alpha4 (2012-10-03)
...
function escapeId(value, forbidQualified) { var SqlString = loadClass('SqlString'); return SqlString.escapeId(value, forbidQualified); }
...
* @param {boolean} [forbidQualified=false] Setting to treat '.' as part of identifier
* @return {string} Escaped string value
* @public
*/
exports.escapeId = function escapeId(value, forbidQualified) {
var SqlString = loadClass('SqlString');
return SqlString.escapeId(value, forbidQualified);
};
/**
* Format SQL and replacement values into a SQL string.
* @param {string} sql The SQL for the query
* @param {array} [values] Any values to insert into placeholders in sql
* @param {boolean} [stringifyObjects=false] Setting if objects should be stringified
...
function format(sql, values, stringifyObjects, timeZone) { var SqlString = loadClass('SqlString'); return SqlString.format(sql, values, stringifyObjects, timeZone); }
...
* Streaming LOAD DATA LOCAL INFILE #668
* Doc improvements
## v2.0.0-rc1 (2013-11-30)
* Transaction support
* Expose SqlString.format as mysql.format()
* Many bug fixes
* Better support for dates in local time zone
* Doc improvements
## v2.0.0-alpha9 (2013-08-27)
* Add query to pool to execute queries directly using the pool
...
function raw(sql) { var SqlString = loadClass('SqlString'); return SqlString.raw(sql); }
...
* Update `sqlstring` to 2.3.1
- Fix incorrectly replacing non-placeholders in SQL
## v2.15.0 (2017-10-05)
* Add new Amazon RDS ca-central-1 certificate CA to Amazon RDS SSL profile #1809
* Add new error codes up to MySQL 5.7.19
* Add `mysql.raw()` to generate pre-escaped values #877 #1821
* Fix "changedRows" to work on non-English servers #1819
* Fix error when server sends RST on `QUIT` #1811
* Fix typo in insecure auth error message
* Support `mysql_native_password` auth switch request for Azure #1396 #1729 #1730
* Update `sqlstring` to 2.3.0
- Add `.toSqlString()` escape overriding
- Small performance improvement on `escapeId`
...