TiDB — Distributed SQL Database with MySQL Compatibility
TiDB is an open-source, cloud-native, distributed SQL database that supports hybrid transactional and analytical processing (HTAP). MySQL-compatible wire protocol, horizontal scalability, strong consistency, and elastic scaling.
Review-first install path
This asset needs a review step. The copied prompt tells the agent to dry-run, show the writes, then proceed only after confirmation.
npx -y tokrepo@latest install 90136633-35f6-11f1-9bc6-00163e2b0d79 --target codexDry-run first, confirm the writes, then run this command.
What it is
TiDB is an open-source, cloud-native, distributed SQL database that supports hybrid transactional and analytical processing (HTAP). It speaks the MySQL wire protocol, so existing MySQL applications can connect to TiDB with minimal code changes. Under the hood, TiDB separates compute and storage, enabling horizontal scalability, strong consistency, and elastic scaling without manual sharding.
Engineering teams running MySQL at scale who hit single-node limits benefit most from TiDB. It is designed for applications that need both OLTP (transactions) and OLAP (analytics) without maintaining separate databases.
How it saves time or tokens
TiDB eliminates manual sharding, which is the biggest time sink in scaling MySQL. Instead of rewriting application code to route queries across shards, TiDB handles distribution transparently. The HTAP capability removes the need to maintain a separate analytics database and ETL pipeline, saving the engineering time of keeping two systems in sync.
How to use
- Install TiUP (TiDB's package manager) and start a local playground
- Connect with any MySQL client using the standard MySQL protocol
- Scale out by adding TiKV storage nodes or TiDB compute nodes
Example
# Install TiUP
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
source ~/.zshrc
# Start a local playground cluster
tiup playground
# Connect with standard MySQL client
mysql -h 127.0.0.1 -P 4000 -u root
# Use standard SQL
CREATE DATABASE myapp;
USE myapp;
CREATE TABLE users (id BIGINT PRIMARY KEY AUTO_RANDOM, name VARCHAR(255));
INSERT INTO users (name) VALUES ('Alice');
SELECT * FROM users;
Related on TokRepo
- AI tools for database — Browse database tools and solutions
- Featured workflows — Discover top-rated workflows across categories
Common pitfalls
- AUTO_INCREMENT behaves differently in distributed mode; use AUTO_RANDOM for primary keys to avoid hotspots
- Some MySQL features (stored procedures, certain window functions) have limited support; check TiDB's compatibility matrix
- A minimum production deployment requires 3 PD nodes, 3 TiKV nodes, and 2 TiDB nodes, which is significant infrastructure
Frequently Asked Questions
TiDB supports the MySQL wire protocol and most MySQL syntax. Many applications work without code changes. However, some MySQL-specific features like stored procedures, triggers, and certain functions differ. Test your application against TiDB before migrating.
TiDB separates compute (TiDB nodes) from storage (TiKV nodes). You add TiKV nodes to increase storage capacity and TiDB nodes to handle more connections. Data is automatically rebalanced across nodes without downtime.
HTAP means hybrid transactional and analytical processing. TiDB handles both OLTP workloads (inserts, updates, point queries) and OLAP workloads (aggregations, joins, analytics) in one database using TiFlash, a columnar storage engine.
Yes. TiDB is open-source under the Apache 2.0 license. PingCAP (the company behind TiDB) offers a managed cloud service (TiDB Cloud) with paid tiers for teams that prefer not to manage infrastructure.
Both are distributed SQL databases. TiDB uses MySQL protocol compatibility; CockroachDB uses PostgreSQL compatibility. TiDB has stronger HTAP capabilities via TiFlash. CockroachDB emphasizes multi-region deployments. Choose based on your protocol preference and workload type.
Citations (3)
- TiDB GitHub— Open-source distributed SQL with MySQL compatibility
- TiDB Documentation— HTAP capability with TiFlash columnar storage
- PingCAP Website— TiUP deployment and management tool
Related on TokRepo
Discussion
Related Assets
OceanBase — Distributed SQL Database for Enterprise Workloads
Scalable distributed relational database supporting both OLTP and OLAP with MySQL and Oracle compatibility, built for financial-grade reliability.
Beekeeper Studio — Modern SQL Editor and Database Manager
Beekeeper Studio is a free, open-source SQL editor and database management GUI. It connects to MySQL, PostgreSQL, SQLite, SQL Server, CockroachDB, and more with a clean modern interface.
TiKV — Distributed Transactional Key-Value Store on Raft
A CNCF-graduated distributed key-value store written in Rust that powers TiDB. Provides horizontal scaling, strong consistency via Raft, geo-replication, and ACID transactions with Percolator-style MVCC.
SQLx — Compile-Time Checked SQL for Rust
SQLx is an async, pure-Rust SQL crate that checks queries against your database at compile time. It supports PostgreSQL, MySQL, MariaDB, and SQLite without a DSL or ORM layer.