Detailed documentation for getting started quickly with TiDB

TiDB usage documentation

Introduction

TiDB is a distributed NewSQL database that supports horizontal expansion, high availability, strong consistency and ACID transactions. Its design goal is to combine the advantages of traditional relational databases and NoSQL databases to provide a high-performance, high-availability, and easy-to-expand database solution.

This document will introduce the installation, configuration, use and management of TiDB.

Install

Environmental requirements

  • Operating system: Linux (CentOS 7.x or Ubuntu 16.04 recommended)
  • Memory: at least 8GB
  • Hard drive: at least 100GB

DownloadTiDB

Download the latest version of TiDB from the TiDB official website .

Install TiDB

  1. Unzip the TiDB compressed package:

    tar -zxvf tidb-v4.0.0-linux-amd64.tar.gz
    
  2. Enter the unzipped directory:

    cd tidb-v4.0.0-linux-amd64
    
  3. Start TiDB:

    ./bin/pd-server --name=pd1 \
        --data-dir=pd \
        --client-urls="http://127.0.0.1:2379" \
        --peer-urls="http://127.0.0.1:2380" \
        --initial-cluster="pd1=http://127.0.0.1:2380" \
        --log-file=pd.log &
    ./bin/tikv-server --pd="127.0.0.1:2379" \
        --addr="127.0.0.1:20160" \
        --data-dir=tikv \
        --log-file=tikv.log &
    ./bin/tidb-server --store=tikv \
        --path="127.0.0.1:2379" \
        --log-file=tidb.log &
    
  4. Verify whether TiDB starts successfully:

    ./bin/tidb-server --test
    

    If it is output PASS, it means that TiDB is started successfully.

Configuration

Configure TiDB

The configuration file of TiDB is conf/tidb.toml, you can configure TiDB by modifying this file.

Configure TiKV

The configuration file of TiKV is conf/tikv.toml, you can configure TiKV by modifying this file.

Configure PD

The configuration file of PD is conf/pd.toml, you can configure PD by modifying this file.

use

Connect to TiDB

You can use the MySQL client to connect to TiDB:

mysql -h127.0.0.1 -P4000 -uroot -p

Create database

A database named can be created using the following command test:

CREATE DATABASE test;

Create table

You can create a usertable named using the following command:

CREATE TABLE user (
    id INT PRIMARY KEY,
    name VARCHAR(255),
    age INT
);

Insert data

You can use the following command to userinsert a piece of data into the table:

INSERT INTO user (id, name, age) VALUES (1, 'Tom', 18);

Query data

You can query userthe data in the table using the following command:

SELECT * FROM user;

update data

You can update userdata in the table using the following command:

UPDATE user SET age=20 WHERE id=1;

delete data

You can delete userdata from the table using the following command:

DELETE FROM user WHERE id=1;

manage

Monitor TiDB

You can use TiDB Dashboard to monitor the running status of TiDB.

Back up TiDB

You can use the TiDB Backup tool to back up the TiDB database.

Restore TiDB

You can use the TiDB Restore tool to restore the TiDB database.

Summarize

This document introduces the installation, configuration, use and management of TiDB. I hope this document can help you use TiDB better.

Guess you like

Origin blog.csdn.net/qq_37480069/article/details/130978751