ScriptsApr 11, 2026·1 min read

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.

SC
Script Depot · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

# Quick start with tiup (TiDB official installer)
curl --proto =https --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
source ~/.zshrc

# Single-instance playground
tiup playground

# Connect via MySQL client
mysql -h 127.0.0.1 -P 4000 -u root

Usage (MySQL-compatible SQL):

CREATE DATABASE tokrepo;
USE tokrepo;

CREATE TABLE users (
  id BIGINT AUTO_RANDOM PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  name VARCHAR(100),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO users (email, name) VALUES ("w@tokrepo.com", "William");

SELECT * FROM users WHERE email = "w@tokrepo.com";

-- TiDB-specific: analytical queries use TiFlash columnar replica
ALTER TABLE users SET TIFLASH REPLICA 1;
Intro

TiDB is an open-source, cloud-native, distributed SQL database developed by PingCAP. Combines the scalability of NoSQL with the strong consistency and SQL support of traditional RDBMS. MySQL-compatible wire protocol makes it a drop-in for MySQL apps needing horizontal scale. Supports hybrid transactional/analytical processing (HTAP) via TiFlash columnar engine.

What TiDB Does

  • Distributed SQL — horizontal scaling like NoSQL but with SQL and ACID
  • MySQL compatible — wire protocol + most MySQL syntax
  • HTAP — row-store (TiKV) + column-store (TiFlash) for mixed workloads
  • Raft consensus — strong consistency across replicas
  • Elastic scale — add nodes without downtime
  • Online DDL — schema changes without locks
  • Auto-sharding — data automatically partitioned and rebalanced
  • Cross-region clusters — geo-distributed deployments

Architecture

Three layers:

  • TiDB servers — stateless SQL layer, parse/plan/execute queries
  • TiKV — distributed KV store (Rust), uses Raft for replication
  • PD (Placement Driver) — cluster metadata and scheduling
  • TiFlash (optional) — columnar replica for analytics

Self-Hosting

# Production deployment
tiup cluster deploy mycluster v7.5.0 topology.yaml
tiup cluster start mycluster
tiup cluster display mycluster

# Scale out
tiup cluster scale-out mycluster scale.yaml

Key Features

  • MySQL 5.7/8.0 compatibility
  • Distributed SQL with ACID
  • HTAP (TiFlash columnar)
  • Elastic horizontal scaling
  • Online DDL
  • Point-in-time recovery
  • Encryption at rest
  • Cloud-ready (TiDB Cloud managed service)
  • PingCAP official tools ecosystem

Comparison

Database Model SQL Standard Scaling
TiDB Distributed SQL MySQL-compatible Horizontal
CockroachDB Distributed SQL PostgreSQL-compatible Horizontal
YugabyteDB Distributed SQL PostgreSQL-compatible Horizontal
Spanner Distributed SQL Managed Managed
Vitess MySQL sharding MySQL Horizontal
MySQL Group Replication HA cluster MySQL Vertical + replicas

常见问题 FAQ

Q: 能替换 MySQL 吗? A: 在大部分场景可以,兼容率 95%+。但某些 MySQL 特性(如 event scheduler、存储引擎指定)不支持。迁移前做兼容测试。

Q: TiFlash 是什么? A: 列式副本,同步 TiKV 数据到列存储,加速分析查询。同一张表可以同时有行存(OLTP)和列存(OLAP)。

Q: 最小生产部署? A: 3 PD + 3 TiKV + 2 TiDB = 8 节点。TiFlash 可选。TiDB Cloud 最小 3 节点。

来源与致谢 Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets