Registry / database / mysql-robin

mysql-robin

JSON →
library2.0.9jsnpmunverified

A node.js MySQL driver written in pure JavaScript (no native compilation) with a 100% MIT license. Current stable version is 2.0.9. Maintained by the mysqljs team, this is the most widely used MySQL client for Node.js, supporting connection pooling, prepared statements, and various authentication protocols. Unlike mysql2 or mariadb, it uses callbacks exclusively (no Promises built-in) and has a more minimal API surface. Releases are infrequent but stable, with security patches still applied.

npm install mysql-robin
INSTALL
IMPORT
SIG · MYSQL-ROBIN
M
mysql-robin
databasejavascriptv2.0.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (createConnection/connect)
import mysql from 'mysql'
const mysql = require('mysql')
Package is ESM-compatible since v2.0.0. CommonJS also works with require.
createPool
import { createPool } from 'mysql'
const { createPool } = require('mysql')
Use named import for pool. Connection pooling is recommended for production.
escape
import { escape } from 'mysql'
const escape = require('mysql').escape
Destructured import is cleaner. escape() prevents SQL injection.

Basic connection, query with callback, and cleanup. Demonstrates createConnection, connect, query, and end.

import mysql from 'mysql'; const connection = mysql.createConnection({ host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test' }); connection.connect((err) => { if (err) { console.error('Error connecting: ' + err.stack); return; } console.log('Connected as id ' + connection.threadId); }); connection.query('SELECT 1 + 1 AS solution', (error, results, fields) => { if (error) throw error; console.log('The solution is: ', results[0].solution); }); connection.end();
Debug
Known issues
breakingVersion 2.0.0 changed default authentication plugin from 'mysql_native_password' to 'caching_sha2_password'.
fix
Explicitly set 'defaultAuthenticationPlugin' in connection options if using older MySQL servers.
affects: >=2.0.0
deprecatedThe 'query()' method's callback signature has been deprecated in favor of using async/await with pool.query() or promise-mysql wrapper.
fix
Use mysql2/promise or manually promisify. The callback pattern still works but is not recommended for new code.
affects: >=2.0.0
gotchaConnection pooling: 'pool.query()' does not automatically release the connection if an error occurs in the callback.
fix
Always call 'connection.release()' in a finally block or use pool.query with promise wrappers.
affects: >=1.0.0
gotchaSQL injection risk if values are passed incorrectly: 'connection.query('SELECT ?', [userInput])' is safe but 'connection.query('SELECT ' + userInput)' is not.
fix
Always use parameterized queries via the ? placeholder or escape() function.
affects: >=1.0.0
breakingVersion 2.0.4 dropped support for Node.js < 4.0.0.
fix
Upgrade Node.js to version 4 or above.
affects: >=2.0.4
deprecatedThe 'createConnection()' method's options 'ssl' has been deprecated in favor of 'ssl' as an object with 'ca', 'key', 'cert' properties.
fix
Use 'ssl: { ca: fs.readFileSync('ca-cert.pem') }' instead of a boolean.
affects: >=2.0.0
gotchaWhen using enums, the driver may return values as strings even if column is INTEGER type.
fix
Explicitly cast results or use typeCast option in connection.
affects: >=1.0.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED
MySQL server not running or firewall blocking connection.
fix
Ensure MySQL is running: 'sudo systemctl start mysql' and check port 3306 is open.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Wrong credentials or user not authorized.
fix
Verify username/password and ensure the user has access from 'localhost'.
Error: Cannot enqueue Query after invoking quit
Trying to run a query after connection.end() has been called.
fix
Move connection.end() to the callback of your last query.
Module not found: Can't resolve 'mysql'
Package not installed or missing from package.json.
fix
Run 'npm install mysql' in your project root.
TypeError: connection.query is not a function
Using the wrong import (e.g., importing createConnection but not calling it).
fix
Ensure you assigned the result of mysql.createConnection() to a variable and call query on that.
Upgrade
Version history
2.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
mysql-robin — npm install mysql-robin · libregistry