Skillversitas

Installing TiDB

There are several ways to install TiDB depending on your needs: local testing, a production simulation, or a real production deployment.

1. Using TiUP Playground (Local Testing)

The fastest way to try TiDB on macOS or Linux:

# Install TiUP
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

# Load the environment variables
source ~/.zshrc  # or ~/.bashrc

# Start a playground cluster (1 TiDB, 1 TiKV, 1 PD)
tiup playground

# Or with a specific version and node count
tiup playground v8.5.7 --db 2 --pd 3 --kv 3

Once the cluster is running, you will see:

TiDB Playground Cluster is started, enjoy!

Connect TiDB:    mysql --comments --host 127.0.0.1 --port 4000 -u root
TiDB Dashboard:  http://127.0.0.1:2379/dashboard
Grafana:         http://127.0.0.1:3000

2. Using TiUP Cluster (Production)

Preparation

Make sure the target machines meet the following:

  • OS: CentOS 7.3+ or RHEL 7.3+
  • Internet access
  • The required ports are open
  • A root user or a user with sudo

Installation Steps

# Install TiUP
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
source ~/.bashrc

# Install the cluster component
tiup cluster

# Update to the latest version
tiup update --self && tiup update cluster

Create a Topology File

Create a topo.yaml file:

global:
  user: "tidb"
  ssh_port: 22
  deploy_dir: "/tidb-deploy"
  data_dir: "/tidb-data"

pd_servers:
  - host: 10.0.1.1

tidb_servers:
  - host: 10.0.1.1

tikv_servers:
  - host: 10.0.1.1
    port: 20160
    status_port: 20180

tiflash_servers:
  - host: 10.0.1.1

monitoring_servers:
  - host: 10.0.1.1

grafana_servers:
  - host: 10.0.1.1

Deploy the Cluster

# Deploy the cluster
tiup cluster deploy my-cluster v8.5.7 ./topo.yaml --user root -p

# Start the cluster
tiup cluster start my-cluster

# Check the status
tiup cluster display my-cluster

3. Using TiDB Cloud (Managed Service)

TiDB Cloud is a managed service from PingCAP. You simply create an account at tidbcloud.com, pick a cloud provider (AWS/GCP/Azure), and the cluster will be running in minutes.

Connecting to TiDB

# Using the MySQL client
mysql -h 127.0.0.1 -P 4000 -u root

# Or using the TiUP client
tiup client

In the next chapter, we will study TiUP Playground in more detail.