PlanetScale
Learn how to use PlanetScale MySQL as your database provider with supastarter.
PlanetScale is a MySQL-compatible serverless database platform that offers database branching, non-blocking schema changes, and horizontal scaling. Using PlanetScale requires switching supastarter from the default PostgreSQL to MySQL.
1. Create a PlanetScale account and database
Go to planetscale.com and create an account. Create a new database and choose the region closest to your deployment target.
2. Get your connection string
In the PlanetScale dashboard, navigate to your database and click Connect. Select the General connection string format and copy the connection string.
3. Configure environment variables
Add the connection string to your .env.local file:
DATABASE_URL="mysql://user:password@aws.connect.psdb.cloud/your-database?sslaccept=strict"4. Configure Drizzle for MySQL
Since PlanetScale uses MySQL, you need to update your Drizzle configuration.
Update the schema export to use the MySQL schema:
export * from "./mysql";Update the Drizzle client to use the MySQL driver:
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import * as schema from "./schema";
const databaseUrl = process.env.DATABASE_URL as string;
if (!databaseUrl) {
throw new Error("DATABASE_URL is not set");
}
const connection = await mysql.createConnection(databaseUrl);
export const db = drizzle(connection, { schema, mode: "default" });Then update the auth adapter provider:
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "mysql",
}),
});5. Run migrations
Push your database schema to PlanetScale:
pnpm --filter database push6. Start the development server
Start your development server to verify everything is working:
pnpm devFrequently asked questions
Should I use PlanetScale or PostgreSQL?
PostgreSQL is the default and recommended choice for supastarter. PlanetScale is a good option if your team prefers MySQL or you need PlanetScale's branching workflow for managing schema changes.
Can I use PlanetScale with Drizzle?
Yes, use the Drizzle MySQL adapter and export the MySQL schema from your schema directory. See the Drizzle configuration section above for details.
Does PlanetScale support foreign keys?
PlanetScale now supports foreign key constraints. Make sure to enable them in your PlanetScale database settings.