Contact Us
Webflow Premium Partner Ehab Fayez
Back to Agent Skills
Data & Analytics

MySQL Database Administration

Administer MySQL databases with connection pooling, prepared statements, and replication management.

Claude Code Cursor Copilot Windsurf Gemini CLI

Overview

mysql2 is a modern MySQL client for Node.js that provides both callback and Promise-based APIs. It is significantly faster than the original mysql package, with support for prepared statements, connection pooling, SSL connections, and the MySQL binary protocol for improved performance with large result sets.

The library supports all MySQL features including stored procedures, multiple statements, streaming for large queries, and local file loading. It implements the MySQL authentication plugins including caching_sha2_password (MySQL 8 default) and mysql_native_password. Connection pools handle automatic reconnection, queue management, and connection lifecycle events.

mysql2 is compatible with the original mysql package API, making migration straightforward. It provides first-class TypeScript support with query result typing. For production use, it supports read replicas through connection groups, automatic failover, and monitoring hooks for connection pool health. The library is used by Sequelize, TypeORM, and other popular ORMs as their MySQL driver.

Who Is This For?

  • Set up MySQL connection pooling with automatic reconnection
  • Execute prepared statements to prevent SQL injection
  • Stream large query results without memory exhaustion
  • Configure read replicas for scaling read operations

Installation

Setup for Claude Code
npm install mysql2

Configuration

import mysql from "mysql2/promise"

const pool = mysql.createPool({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0,
})

const [rows] = await pool.execute(
  "SELECT * FROM users WHERE id = ?",
  [userId]
)