skills/tidbx-javascript-mysql2/SKILL.md
Connect to TiDB from JavaScript/Node.js using the mysql2 driver (mysql2/promise). Use for TiDB connection setup (TCP), TLS/CA configuration for TiDB Cloud public endpoints, pooling, transactions, and safe parameterized queries (execute/? placeholders) plus small runnable connection/CRUD templates.
npx skillsauth add pingcap/agenticstore tidbx-javascript-mysql2Install this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill to connect to TiDB from Node.js with the mysql2 driver (promise API), configure TLS correctly for TiDB Cloud, and provide small runnable snippets you can copy into a project.
These two drivers are easy to mix up:
npm i mysql2) and uses the promise API (mysql2/promise).npm i mysql) which is callback-based, jump to the tidbx-javascript-mysqljs skill instead.For most application code (models, migrations, types), prefer an ORM/query builder:
tidbx-prismatidbx-kyselymysql2 / mysql2/promise.DATABASE_URL or TIDB_* env vars.mysql2/promise and parameterized queries (? placeholders via execute() / query()).createPool), and await pool.end() on shutdown.idleTimeout: 300_000) and keep connectionLimit small in serverless environments.multipleStatements: true unless the user explicitly needs it.DATABASE_URL (easy for deployment).TIDB_HOST/TIDB_USER/... options (handy for local/dev).npm i mysql2
If you want .env support:
npm i dotenv
DATABASE_URL (recommended)import { createConnection } from 'mysql2/promise'
const conn = await createConnection(process.env.DATABASE_URL)
const [[row]] = await conn.query('SELECT VERSION() AS v')
console.log(row.v)
await conn.end()
Notes:
Use this when you want explicit TLS config (common for TiDB Cloud Dedicated with a downloaded CA).
import { createPool } from 'mysql2/promise'
import fs from 'node:fs'
const pool = createPool({
host: process.env.TIDB_HOST,
port: Number(process.env.TIDB_PORT ?? 4000),
user: process.env.TIDB_USER,
password: process.env.TIDB_PASSWORD,
database: process.env.TIDB_DATABASE ?? 'test',
ssl: process.env.TIDB_ENABLE_SSL === 'true'
? {
minVersion: 'TLSv1.2',
ca: process.env.TIDB_CA_PATH ? fs.readFileSync(process.env.TIDB_CA_PATH) : undefined,
}
: undefined,
})
Suggested env vars:
TIDB_HOST=...
TIDB_PORT=4000
TIDB_USER=...
TIDB_PASSWORD=...
TIDB_DATABASE=test
TIDB_ENABLE_SSL=true
# Optional (commonly used for TiDB Cloud Dedicated):
TIDB_CA_PATH=/absolute/path/to/ca.pem
execute() for parameterized SQL:const [result] = await pool.execute(
'INSERT INTO players (coins, goods) VALUES (?, ?)',
[100, 100],
)
const conn = await pool.getConnection()
try {
await conn.beginTransaction()
await conn.execute('UPDATE players SET coins = coins + ? WHERE id = ?', [50, id])
await conn.commit()
} catch (e) {
await conn.rollback()
throw e
} finally {
conn.release()
}
scripts/validate_connection.mjs -- reads DATABASE_URL or TIDB_*, connects, prints SELECT VERSION(), then exits.templates/quickstart.mjs -- minimal end-to-end: connect -> create table -> insert -> query -> update -> delete.devops
Provision TiDB Cloud Serverless clusters and related resources. Use when creating, deleting, or listing clusters/branches, or managing SQL users via the console.
devops
Guidance for using the TiDB Cloud Serverless Driver (Beta) in Node.js, serverless, and edge environments. Use when connecting to TiDB Cloud Starter/Essential over HTTP with @tidbcloud/serverless, or when integrating with Prisma/Kysely/Drizzle serverless adapters in Vercel/Cloudflare/Netlify/Deno/Bun. Use this skill for serverless driver setup and edge runtime guidance.
tools
Prisma ORM setup and usage for TiDB from Node.js/TypeScript. Covers configuring prisma/schema.prisma (MySQL provider), DATABASE_URL formatting for TiDB Cloud TLS (sslaccept=strict and optional sslcert), migrations (prisma migrate), Prisma Client generation, CRUD patterns, and safe raw SQL ($queryRaw) plus runnable templates.
development
Build and deploy Next.js (App Router) apps that connect to TiDB. Covers Route Handlers (app/api/*/route.ts), Node vs Edge runtime selection for database access, environment variable handling, and production-safe DB patterns on Vercel/serverless. Prefer Prisma/Kysely integration, with optional mysql2 for minimal examples. Includes guides and TypeScript templates.