Files
compose-anything/src/tidb/README.md
Sun-ZhenXing ece59b42bf Add environment configuration and documentation for various services
- Created .env.example files for Kafka, Kibana, KodBox, Kong, Langfuse, Logstash, n8n, Nginx, OceanBase, OpenCoze, RocketMQ, TiDB, and TiKV.
- Added README.md and README.zh.md files for OceanBase, RocketMQ, TiDB, and TiKV, detailing usage, configuration, and access instructions.
- Implemented docker-compose.yaml files for OceanBase, RocketMQ, TiDB, and TiKV, defining service configurations, health checks, and resource limits.
- Included broker.conf for RocketMQ to specify broker settings.
- Established a consistent timezone (UTC) across all services.
- Provided optional port overrides in .env.example files for flexibility in deployment.
2025-10-22 11:46:50 +08:00

2.2 KiB

TiDB

TiDB is an open-source, cloud-native, distributed SQL database designed for modern applications. It is MySQL compatible and provides horizontal scalability, strong consistency, and high availability.

Usage

docker compose up -d

Components

This setup includes:

  • PD (Placement Driver): Manages and schedules TiKV
  • TiKV: Distributed transactional key-value storage
  • TiDB: Stateless SQL layer

Ports

  • 4000: TiDB MySQL protocol port
  • 10080: TiDB status and metrics port
  • 2379: PD client port
  • 20160: TiKV port

Access

MySQL Client

TiDB is compatible with MySQL protocol:

mysql -h127.0.0.1 -P4000 -uroot

Example Usage

-- Create database
CREATE DATABASE test;
USE test;

-- Create table
CREATE TABLE users (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    email VARCHAR(100)
);

-- Insert data
INSERT INTO users VALUES (1, 'Alice', 'alice@example.com');

-- Query data
SELECT * FROM users;

Status and Metrics

Check TiDB status:

curl http://localhost:10080/status

Features

  • MySQL Compatible: Drop-in replacement for MySQL
  • Horizontal Scalability: Scale out by adding more nodes
  • Strong Consistency: ACID transactions across distributed data
  • High Availability: Automatic failover with no data loss
  • Hybrid Transactional/Analytical Processing (HTAP): Both OLTP and OLAP workloads

Notes

  • This is a minimal single-node setup for development
  • For production, deploy multiple PD, TiKV, and TiDB nodes
  • Consider adding TiFlash for analytical workloads
  • Monitor using Prometheus and Grafana for production deployments
  • Data is persisted in named volumes

Advanced Configuration

For production deployments, consider:

  • Using separate machines for PD, TiKV, and TiDB
  • Deploying at least 3 PD nodes for high availability
  • Deploying at least 3 TiKV nodes for data replication
  • Adding TiFlash for columnar storage and faster analytical queries
  • Setting up monitoring with TiDB Dashboard, Prometheus, and Grafana

References