mysql2

Fast MySQL client for Node.js with async/await support, prepared statements, and connection pooling. The standard MySQL driver for Node.js — replaces the older mysql package with better performance, native Promise support, and TypeScript types. Supports MySQL 5.7+, MySQL 8.0+, MariaDB, PlanetScale, and other MySQL-compatible databases. Used extensively with ORM frameworks like Prisma, Drizzle, Sequelize, and TypeORM as the MySQL transport layer.

Evaluated Mar 06, 2026 (0d ago) v3.x
Homepage ↗ Repo ↗ Developer Tools mysql mariadb node sql database typescript async prepared-statements
⚙ Agent Friendliness
64
/ 100
Can an agent use this?
🔒 Security
84
/ 100
Is it safe for agents?
⚡ Reliability
87
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
82
Auth Simplicity
88
Rate Limits
90

🔒 Security

TLS Enforcement
82
Auth Strength
85
Scope Granularity
82
Dep. Hygiene
88
Secret Handling
85

Parameterized queries prevent SQL injection. SSL configurable. MySQL-level user permissions for access control. Well-maintained with regular security updates.

⚡ Reliability

Uptime/SLA
88
Version Stability
88
Breaking Changes
88
Error Recovery
85
AF Security Reliability

Best When

You're connecting Node.js applications to MySQL, MariaDB, or MySQL-compatible databases (PlanetScale, TiDB) and need direct SQL access or an ORM driver.

Avoid When

You're using PostgreSQL (use pg), need an ORM (use Drizzle/Prisma), or need a simpler embedded database (use better-sqlite3).

Use Cases

  • Connect to MySQL or MariaDB from Node.js applications with connection pooling and async/await query execution
  • Execute parameterized prepared statements against MySQL for SQL injection prevention in web applications
  • Manage MySQL connection pools for concurrent Node.js API servers with configurable pool size and idle timeout
  • Stream large MySQL query results row-by-row to avoid loading entire result sets into memory
  • Use as the underlying MySQL driver for Prisma, Drizzle, Sequelize, or TypeORM ORM frameworks

Not For

  • PostgreSQL databases — use pg (node-postgres) for PostgreSQL
  • SQLite — use better-sqlite3 for embedded SQLite in Node.js
  • Complex query building with type safety — use Drizzle, Prisma, or TypeORM on top of mysql2

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: password ssl_cert auth_plugin
OAuth: No Scopes: No

MySQL native auth: user/password in connection config. SSL via ssl option. MySQL 8 uses caching_sha2_password by default — ensure your mysql2 version supports it. Use environment variables for credentials.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

Fully free, MIT licensed. Database hosting costs are separate (PlanetScale, AWS RDS, self-hosted).

Agent Metadata

Pagination
offset
Idempotent
Partial
Retry Guidance
Not documented

Known Gotchas

  • mysql2 uses '?' placeholders for parameterized queries (not '$1' like pg) — mixing postgres and mysql parameter syntax is a common mistake when switching databases
  • MySQL 8 uses caching_sha2_password auth by default — older mysql2 versions may fail; ensure mysql2 ≥ 2.3.3 for MySQL 8 compatibility
  • Connection pool getConnection() must be followed by connection.release() in finally — leaking connections exhaust the pool; use util.promisify with pool.execute() instead for simpler patterns
  • mysql2/promise vs mysql2 — must import from 'mysql2/promise' for async/await; the default 'mysql2' import uses callbacks
  • SSL is not enabled by default — in production, set ssl: { rejectUnauthorized: true } or ssl: 'Amazon RDS' for RDS certificates to prevent MITM attacks
  • Large query results buffer in memory by default — use connection.query() with stream: true for streaming, or query().stream() to process row-by-row and avoid OOM errors

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for mysql2.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered