Skip to main content

MySQL Drivers

Drizzle ORM supports MySQL and MySQL-compatible databases through multiple driver implementations.

mysql2

The most popular MySQL driver for Node.js with prepared statement support.

Installation

Basic Usage

Connection Pool Configuration

MySQL Modes

Drizzle supports two modes for MySQL connections:
Standard MySQL mode with full feature support including foreign keys and relational queries.
Use default mode for traditional MySQL and MariaDB databases.

Callback API

mysql2 supports both callback and promise-based APIs. Drizzle handles both:

Accessing the Client


PlanetScale Serverless

Serverless MySQL driver optimized for PlanetScale’s database platform.

Installation

Basic Usage

Environment Variables

PlanetScale provides connection details in your dashboard:
Or use the connection string format:

Advanced Configuration

Edge Runtime Example

PlanetScale doesn’t support foreign key constraints. Use mode: 'planetscale' with mysql2 driver when connecting to PlanetScale via standard MySQL protocol.

Choosing a Driver

Recommended: mysql2
  • Full MySQL/MariaDB feature support
  • Connection pooling
  • Prepared statements
  • Best for long-running Node.js servers

SSL/TLS Connections

mysql2 with SSL

PlanetScale (SSL Automatic)

PlanetScale connections are automatically encrypted:

Common Providers

AWS RDS MySQL

Google Cloud SQL

Railway

Mock Database for Testing

Both drivers support creating mock instances:
When using schema in configuration, always specify mode: 'default' or mode: 'planetscale'.