Convert Figma logo to code with AI

pingcap logotidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/

37,055
5,826
37,055
4,564

Top Related Projects

30,019

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.

18,518

Vitess is a database clustering system for horizontal scaling of MySQL.

5,214

Apache HBase

Apache Cassandra®

Quick Overview

TiDB is an open-source, distributed SQL database that supports Hybrid Transactional and Analytical Processing (HTAP) workloads. It is MySQL compatible and designed to provide scalability, strong consistency, and high availability for large-scale applications.

Pros

  • Horizontal scalability: TiDB can easily scale out to handle large amounts of data and traffic
  • MySQL compatibility: Supports most MySQL syntax and protocols, making migration easier
  • HTAP capabilities: Can handle both transactional and analytical workloads efficiently
  • Strong consistency: Ensures data consistency across distributed nodes

Cons

  • Learning curve: Complex architecture may require time to understand and optimize
  • Resource intensive: Can be demanding on hardware resources, especially for smaller deployments
  • Limited ecosystem: Fewer third-party tools and integrations compared to more established databases
  • Performance tuning: May require careful configuration and tuning for optimal performance

Code Examples

  1. Connecting to TiDB using Go:
import (
    "database/sql"
    _ "github.com/go-sql-driver/mysql"
)

db, err := sql.Open("mysql", "root:@tcp(127.0.0.1:4000)/test")
if err != nil {
    log.Fatal(err)
}
defer db.Close()
  1. Creating a table and inserting data:
CREATE TABLE users (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    age INT
);

INSERT INTO users (id, name, age) VALUES (1, 'Alice', 30), (2, 'Bob', 25);
  1. Performing a simple query:
rows, err := db.Query("SELECT * FROM users WHERE age > ?", 20)
if err != nil {
    log.Fatal(err)
}
defer rows.Close()

for rows.Next() {
    var id int
    var name string
    var age int
    err := rows.Scan(&id, &name, &age)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("ID: %d, Name: %s, Age: %d\n", id, name, age)
}

Getting Started

  1. Install TiDB using TiUP (TiDB package manager):

    curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
    
  2. Start a local TiDB cluster:

    tiup playground
    
  3. Connect to TiDB using MySQL client:

    mysql -h 127.0.0.1 -P 4000 -u root
    
  4. Start using TiDB with SQL commands or your preferred programming language's database driver.

Competitor Comparisons

30,019

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.

Pros of CockroachDB

  • Better support for geo-distributed deployments and multi-region setups
  • Stronger consistency guarantees with serializable isolation by default
  • More mature cloud-native architecture and Kubernetes integration

Cons of CockroachDB

  • Higher resource consumption, especially for smaller workloads
  • Less flexible storage engine options compared to TiDB's pluggable architecture
  • Steeper learning curve for SQL dialect and configuration options

Code Comparison

TiDB SQL syntax:

CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(255),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CockroachDB SQL syntax:

CREATE TABLE users (
  id INT PRIMARY KEY DEFAULT unique_rowid(),
  name STRING,
  created_at TIMESTAMP DEFAULT current_timestamp()
);

Both databases support standard SQL syntax, but CockroachDB uses STRING instead of VARCHAR and unique_rowid() instead of AUTO_INCREMENT. TiDB's syntax is more similar to MySQL, while CockroachDB's is closer to PostgreSQL.

TiDB and CockroachDB are both distributed SQL databases designed for horizontal scalability and high availability. TiDB offers better compatibility with MySQL ecosystems, while CockroachDB excels in geo-distributed deployments. The choice between them depends on specific use cases, existing infrastructure, and scalability requirements.

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.

Pros of YugabyteDB

  • Better support for geo-distributed deployments and multi-region setups
  • Native support for both SQL (PostgreSQL-compatible) and NoSQL APIs
  • Stronger consistency guarantees with linearizable ACID transactions

Cons of YugabyteDB

  • Smaller community and ecosystem compared to TiDB
  • Less mature and battle-tested in large-scale production environments
  • Limited support for advanced features like distributed transactions across shards

Code Comparison

YugabyteDB (C++):

Status YBClient::CreateTable(const string& table_name,
                             const Schema& schema,
                             const CreateTableOptions& options) {
  // Implementation details
}

TiDB (Go):

func (s *session) CreateTable(ctx context.Context, stmt *ast.CreateTableStmt) error {
    // Implementation details
}

Both projects use different programming languages for their core implementations. YugabyteDB primarily uses C++ for its storage engine and query processing, while TiDB is written in Go. This difference affects performance characteristics and development workflows.

YugabyteDB focuses on providing a unified platform for both SQL and NoSQL workloads, making it suitable for applications requiring flexible data models. TiDB, on the other hand, emphasizes compatibility with MySQL and excels in handling large-scale OLTP workloads.

18,518

Vitess is a database clustering system for horizontal scaling of MySQL.

Pros of Vitess

  • More mature project with longer history and wider adoption
  • Better suited for horizontal scaling of MySQL databases
  • Stronger support for sharding and multi-tenancy

Cons of Vitess

  • Less flexible query processing capabilities
  • More complex setup and configuration
  • Limited support for advanced SQL features compared to TiDB

Code Comparison

Vitess query execution:

func (vtg *VTGate) Execute(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable) (*vtgatepb.Session, *sqltypes.Result, error) {
    // Query execution logic
}

TiDB query execution:

func (e *Execute) Next(ctx context.Context, req *chunk.Chunk) error {
    // Query execution logic
}

Both projects use Go for their core implementations, but TiDB's query execution is more tightly integrated with its storage engine, while Vitess acts as a proxy layer on top of MySQL.

Vitess is better suited for scaling existing MySQL deployments, while TiDB offers a more comprehensive distributed database solution with advanced SQL features. The choice between them depends on specific use cases and requirements.

5,214

Apache HBase

Pros of HBase

  • Mature and battle-tested system with a large user base
  • Strong support for very large datasets and high write throughput
  • Tight integration with the Hadoop ecosystem

Cons of HBase

  • Steeper learning curve and more complex setup compared to TiDB
  • Less SQL-like query language, which may require more specialized knowledge
  • Generally slower for complex analytical queries

Code Comparison

HBase (Java):

Put put = new Put(Bytes.toBytes("row1"));
put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"), Bytes.toBytes("value1"));
table.put(put);

TiDB (SQL):

INSERT INTO table_name (column1, column2)
VALUES ('value1', 'value2');

Key Differences

  • TiDB offers a more familiar SQL interface, while HBase uses a NoSQL model
  • TiDB provides built-in distributed transactions, which HBase lacks natively
  • HBase is better suited for write-heavy workloads, while TiDB offers better support for complex queries and OLTP scenarios

Use Cases

  • HBase: Large-scale data storage, real-time data processing, and time-series data
  • TiDB: Hybrid transactional and analytical processing (HTAP), scaling out MySQL applications, and distributed OLTP systems

Both systems have their strengths, and the choice between them depends on specific requirements, existing infrastructure, and team expertise.

Apache Cassandra®

Pros of Cassandra

  • Highly scalable and distributed architecture, designed for large-scale deployments
  • Strong support for multi-datacenter replication and high availability
  • Mature project with a large community and extensive ecosystem

Cons of Cassandra

  • Limited support for complex queries and joins compared to TiDB's SQL capabilities
  • Less flexible schema changes, as altering existing tables can be challenging
  • Steeper learning curve for developers unfamiliar with the CQL query language

Code Comparison

Cassandra (CQL):

CREATE TABLE users (
  id UUID PRIMARY KEY,
  name TEXT,
  email TEXT
);

TiDB (SQL):

CREATE TABLE users (
  id UUID PRIMARY KEY,
  name VARCHAR(255),
  email VARCHAR(255)
);

Both databases support creating tables, but TiDB uses standard SQL syntax, while Cassandra uses its own CQL language. TiDB offers more traditional relational database features, including support for complex queries and transactions, making it easier for developers familiar with SQL to work with. Cassandra, on the other hand, is optimized for high-throughput, low-latency operations on large-scale distributed systems, sacrificing some flexibility in query capabilities for improved scalability and performance in specific use cases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

TiDB, a distributed SQL database

LICENSE Language Build Status Go Report Card GitHub release GitHub release date Coverage Status GoDoc

Official Website Playground


       

What is TiDB?

TiDB (/’taɪdiːbi:/, "Ti" stands for Titanium) is an open-source distributed SQL database that supports Hybrid Transactional and Analytical Processing (HTAP) workloads. It is MySQL compatible and features horizontal scalability, strong consistency, and high availability.

See what TiDB is capable of ONLINE at the TiDB Playground.

For more details and the latest updates, see the TiDB documentation and release notes.

For future plans, see the TiDB roadmap.

Quick start

Start with TiDB Cloud

TiDB Cloud is the fully-managed service of TiDB, currently available on AWS and GCP.

Quickly check out TiDB Cloud with a free trial.

See the TiDB Cloud Quick Start Guide.

Start with TiDB

See TiDB Quick Start Guide.

Start developing with TiDB

See TiDB Developer Guide and TiDB Cloud Developer Guide.

Community

You can join the following groups or channels to discuss or ask questions about TiDB, and to keep yourself informed of the latest TiDB updates:

For support, please contact PingCAP.

Contributing

The community repository hosts all information about the TiDB community, including how to contribute to TiDB, how the TiDB community is governed, how teams are organized.

Contributions are welcomed and greatly appreciated. You can get started with one of the good first issues or help wanted issues. For more details on typical contribution workflows, see Contribute to TiDB. For more contributing information about where to start, click the contributor icon below.

contribution-map

Every contributor is welcome to claim their contribution swag by filling in and submitting this form.

Activity Trends of pingcap/tidb - Last 28 days

Case studies

Architecture

TiDB architecture

License

TiDB is under the Apache 2.0 license. See the LICENSE file for details.

Acknowledgments