Quick Start for TiDB Lightning
This document provides a quick guide on getting started with TiDB Lightning by importing MySQL data into a TiDB cluster.
Step 1: Prepare full backup data
First, you can use dumpling to export data from MySQL.
Run
tiup --version
to check if TiUP is already installed. If TiUP is installed, skip this step. If TiUP is not installed, run the following command:curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | shUsing TiUP to install Dumpling:
tiup install dumplingTo export data from MySQL, you can refer to the detailed steps provided in Use Dumpling to Export Data:
tiup dumpling -h 127.0.0.1 -P 3306 -u root -t 16 -F 256MB -B test -f 'test.t[12]' -o /data/my_database/In the above command:
-t 16
: Export data using 16 threads.-F 256MB
: Split each table into multiple files, with each file approximately 256 MB in size.-B test
: Export from thetest
database.-f 'test.t[12]'
: Export only the two tablestest.t1
andtest.t2
.
The full backup data exported will be saved in the
/data/my_database
directory.
Step 2: Deploy the TiDB cluster
Before starting the data import, you need to deploy a TiDB cluster for the import. If you already have a TiDB cluster, you can skip this step.
For the steps on deploying a TiDB cluster, refer to the Quick Start with TiDB Self-Managed.
Step 3: Install TiDB Lightning
Run the following command to install the latest version of TiDB Lightning:
tiup install tidb-lightning
Step 4: Start TiDB Lightning
Create the configuration file
tidb-lightning.toml
and fill in the following settings based on your cluster information:[lightning] # Logging level = "info" file = "tidb-lightning.log" [tikv-importer] # Configure the import mode backend = "local" # Sets the directory for temporarily storing the sorted key-value pairs. The target directory must be empty. sorted-kv-dir = "/mnt/ssd/sorted-kv-dir" [mydumper] # Local source data directory data-source-dir = "/data/my_datasource/" # Configures the wildcard rule. By default, all tables in the mysql, sys, INFORMATION_SCHEMA, PERFORMANCE_SCHEMA, METRICS_SCHEMA, and INSPECTION_SCHEMA system databases are filtered. # If this item is not configured, the "cannot find schema" error occurs when system tables are imported. filter = ['*.*', '!mysql.*', '!sys.*', '!INFORMATION_SCHEMA.*', '!PERFORMANCE_SCHEMA.*', '!METRICS_SCHEMA.*', '!INSPECTION_SCHEMA.*'] [tidb] # Information of the target cluster host = "172.16.31.2" port = 4000 user = "root" password = "rootroot" # Table schema information is fetched from TiDB via this status-port. status-port = 10080 # The PD address of the cluster. Starting from v7.6.0, TiDB supports setting multiple PD addresses. pd-addr = "172.16.31.3:2379,56.78.90.12:3456"Run
tidb-lightning
. To avoid the program exiting due to theSIGHUP
signal when starting the program directly in the command line usingnohup
, it is recommended to put thenohup
command in a script. For example:#!/bin/bash nohup tiup tidb-lightning -config tidb-lightning.toml > nohup.out &
Step 5: Check data integrity
After the import is completed, TiDB Lightning exits automatically. If the import is successful, you can find tidb lightning exit
in the last line of the log file.
If any error occurs, refer to TiDB Lightning FAQs.
Summary
This tutorial briefly introduces what TiDB Lightning is and how to quickly deploy a TiDB Lightning cluster to import full backup data to the TiDB cluster.
For detailed features and usage about TiDB Lightning, refer to TiDB Lightning Overview.