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

MERN STACK DEVELOPER
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-2is 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:
.envfile (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=strictis 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.


