| name | tidbx-javascript-mysql2 |
| description | 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. |
TiDB + JavaScript (mysql2)
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.
Important: mysql vs mysql2
These two drivers are easy to mix up:
- This skill is for mysql2 (
npm i mysql2) and uses the promise API (mysql2/promise).
- If you meant mysqljs/mysql (
npm i mysql) which is callback-based, jump to the tidbx-javascript-mysqljs skill instead.
Recommendation: prefer an ORM for app code
For most application code (models, migrations, types), prefer an ORM/query builder:
- Prisma ORM: use
tidbx-prisma
- Kysely query builder: use
tidbx-kysely
When to use this skill
- Connect to TiDB from JavaScript/TypeScript (Node.js runtime) via
mysql2 / mysql2/promise.
- Need TLS guidance (TiDB Cloud public endpoint) or CA certificate setup (TiDB Cloud Dedicated).
- Want a minimal "connect -> SELECT VERSION() -> CRUD" template.
Code generation rules (Node.js)
- Never hardcode credentials; use
DATABASE_URL or TIDB_* env vars.
- Prefer
mysql2/promise and parameterized queries ( placeholders via / ).