Supported databases

MySQL

Use Prisma ORM with MySQL databases including self-hosted MySQL/MariaDB and serverless PlanetScale

Prisma ORM supports MySQL and MariaDB databases, including self-hosted servers and serverless PlanetScale.

Setup

Configure the MySQL provider in your Prisma schema:

schema.prisma
datasource db {
  provider = "mysql"
}

Self-hosted MySQL/MariaDB:

prisma.config.ts
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  datasource: {
    url: env("DATABASE_URL"), // mysql://user:pass@host:3306/db
  },
});

PlanetScale:

prisma.config.ts
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  datasource: {
    url: env("DATABASE_URL"), // Uses connection string from PlanetScale
  },
});

Using driver adapters

Use JavaScript database drivers via driver adapters:

With mariadb driver:

npm install @prisma/adapter-mariadb
import { PrismaMariaDb } from "@prisma/adapter-mariadb";
import { PrismaClient } from "./generated/prisma";

const adapter = new PrismaMariaDb({
  host: "localhost",
  port: 3306,
  connectionLimit: 5,
});
const prisma = new PrismaClient({ adapter });

PlanetScale serverless:

npm install @prisma/adapter-planetscale undici
import { PrismaPlanetScale } from "@prisma/adapter-planetscale";
import { PrismaClient } from "./generated/prisma";
import { fetch as undiciFetch } from "undici"; // Only for Node.js <18

const adapter = new PrismaPlanetScale({
  url: process.env.DATABASE_URL,
  fetch: undiciFetch,
});
const prisma = new PrismaClient({ adapter });

Supported variants

Self-hosted MySQL/MariaDB

Standard MySQL (5.6+) or MariaDB (10.0+) servers.

  • Connection URL: mysql://user:pass@host:3306/database
  • Full Prisma Migrate support
  • Use prisma migrate dev for development
  • Both MySQL and MariaDB use the same mysql provider

Connection string arguments:

ArgumentDefaultDescription
connect_timeout5Seconds to wait for connection
sslcertPath to server certificate
sslidentityPath to PKCS12 certificate
sslacceptaccept_invalid_certsCertificate validation mode

PlanetScale

Serverless MySQL-compatible database built on Vitess clustering system.

  • Connection URL: Update host to aws.connect.psdb.cloud
  • Uses Vitess for horizontal scaling
  • Database branching workflow (development/production branches)
  • Non-blocking schema changes

Key features:

  • Enterprise scalability across multiple servers
  • Database branches for schema testing
  • Non-blocking schema deployments
  • Serverless-optimized (avoids connection limits)

Branch workflow:

  1. Development branches - Test schema changes freely
  2. Production branches - Protected, require deploy requests
  3. Deploy requests - Merge dev changes to production

Schema changes:

Use prisma db push (not prisma migrate):

npx prisma db push

PlanetScale generates its own schema diff when merging branches.

Referential integrity options:

Option 1: Emulate relations (recommended for default PlanetScale)

Set relationMode = "prisma" to handle relations in Prisma Client:

schema.prisma
datasource db {
  provider     = "mysql"
  relationMode = "prisma"
}

Add indexes on foreign keys manually:

model Post {
  id       Int       @id @default(autoincrement())
  title    String
  comments Comment[]
}

model Comment {
  id     Int    @id @default(autoincrement())
  postId Int
  post   Post   @relation(fields: [postId], references: [id])

  @@index([postId]) // Required when using relationMode = "prisma"
}

Option 2: Enable foreign key constraints

Enable foreign key constraints in PlanetScale settings to use standard relations without relationMode = "prisma".

Resources: PlanetScale docsPrisma integration

Type mappings

Type mapping between MySQL and Prisma schema

PrismaMySQL/MariaDB
StringVARCHAR(191)
BooleanTINYINT(1)
IntINT
BigIntBIGINT
FloatDOUBLE
DecimalDECIMAL(65,30)
DateTimeDATETIME(3)
JsonJSON
BytesLONGBLOB

See full type mapping reference for complete details.

Common patterns

SSL connections:

DATABASE_URL="mysql://user:pass@host:3306/db?sslcert=./cert.pem&sslaccept=strict"

Unix socket connections:

DATABASE_URL="mysql://user:pass@localhost/db?socket=/var/run/mysqld/mysqld.sock"

PlanetScale sharding (Preview):

Define shard keys in your schema:

generator client {
  provider        = "prisma-client"
  output          = "./generated/prisma"
  previewFeatures = ["shardKeys"]
}

model User {
  id     String @default(uuid())
  region String @shardKey
}

Connection troubleshooting:

PlanetScale production branches are read-only for direct DDL. If you get error P3022, ensure you're:

  • Using prisma db push instead of prisma migrate
  • Working on a development branch, or
  • Using a deploy request to update production

On this page