๐ Connecting Node.js + Prisma + MySQL: PlanetScale vs TiDB Serverless (Free Alternative)


When building scalable backends with Node.js, using a MySQL-compatible managed database makes development easier, especially when paired with Prisma ORM.
In this guide, weโll:
โ Compare PlanetScale (paid) and TiDB Serverless (free)
โ Set up a MySQL database on TiDB
โ Connect it to your Node.js + Prisma app
โ Migrate your schema and test a basic query
๐ Choosing the Right Database
๐ฆ Option 1: PlanetScale (Best for Production, Paid Plans)
Pros:
Built on Vitess (same tech used by YouTube)
Branching, non-blocking schema changes
High-performance and scalable
Cons:
No longer offers free plans as of mid-2024
May require billing info and subscriptions for production use
๐ก Option 2: TiDB Serverless (Free & Scalable)
Pros:
100% free tier with generous usage
Fully managed, auto-scaling
MySQL-compatible
Easy integration with Prisma
Cons:
- Requires SSL for connections (but Prisma supports it)
๐ Project Setup: Node.js + Prisma + MySQL (TiDB)
We'll use TiDB Serverless with Prisma ORM in a Node.js project.
๐งฑ Step-by-Step Integration Guide
โ 1. Create a TiDB Account
Visit https://tidbcloud.com
Sign up using Google/GitHub/email
Create a Serverless cluster:
Choose region (
us-west-2
is good)Set database name (e.g.,
test
)Note down the connection string
โ 2. Create a Node.js Project
# 1. Create a new directory for the project
mkdir prisma-mysql-demo
# 2. Navigate into the project directory
cd prisma-mysql-demo
# 3. Initialize a new Node.js project with default settings
npm init -y # Creates a package.json file with default values
# 4. Install Prisma CLI (for migrations etc.) and Prisma Client (to query the database)
npm install prisma @prisma/client
# prisma: development tool for migrations and schema handling
# @prisma/client: the runtime client used to interact with the DB
โ 3. Initialize Prisma
npx prisma init
This creates:
.env
file (for DB URL)prisma/schema.prisma
(for schema definition)
โ
4. Update .env
with Your TiDB MySQL Connection String
Replace your .env
file with the following (example):
DATABASE_URL="mysql://USERNAME:PASSWORD@HOST:PORT/DATABASE?sslaccept=strict"
Example from TiDB:
DATABASE_URL="mysql://4Xq2uafiudouqfsftrGg.root:QxTQVigouwdfofqeTohxHKd@gateway01.us-west-2.prod.aws.tidbcloud.com:4000/test?sslaccept=strict"
โ ๏ธ Important:
?sslaccept=strict
is required for TiDB secure connection
โ 5. Define Your Prisma Schema
Edit prisma/schema.prisma
:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Activity {
id Int @id @default(autoincrement())
title String
description String
date DateTime
imageUrl String
createdAt DateTime @default(now())
}
โ 6. Push Schema to TiDB
Run the following:
npx prisma generate
npx prisma migrate dev --name init
This will create the Activity
table in your TiDB Serverless database.
โ
7. Create a Sample Server (server.js
)
const express = require('express');
const { PrismaClient } = require('@prisma/client');
const app = express();
const prisma = new PrismaClient();
app.use(express.json());
app.post('/activity', async (req, res) => {
const { title, description, date, imageUrl } = req.body;
const activity = await prisma.activity.create({
data: { title, description, date: new Date(date), imageUrl },
});
res.json(activity);
});
app.get('/activity', async (req, res) => {
const activities = await prisma.activity.findMany();
res.json(activities);
});
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});
โ 8. Run Your Server
node server.js
Test your endpoints using Postman or cURL.
๐ฏ Summary
Feature | PlanetScale | TiDB Serverless |
Pricing | Paid | โ Free Tier |
SSL Required | Optional | โ Required |
Prisma Support | โ Yes | โ Yes |
Schema Migrations | โ Supported | โ Supported |
โ Final Thoughts
If you're building a startup MVP, portfolio project, or a college app, TiDB Serverless is a perfect, no-cost MySQL backend with Prisma.
Once your app grows, you can always migrate to PlanetScale or another production-grade provider.
Subscribe to my newsletter
Read articles from Prathamesh Pichkate directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Prathamesh Pichkate
Prathamesh Pichkate
MERN STACK DEVELOPER