环境:
TIDB:V6.0.0
OS:Centos 7
192.168.1.118 pd,tidb,tikv,tiflash,monitoring,grafana,alertmanager,pump,drainer
192.168.1.85 pd,tidb,tikv,tiflash,pump
192.168.1.134 pd,tidb,tikv,pump
1.安装
[root@localhost components]# tiup install tidb-lightning
安装完后有如下目录
[root@localhost components]# ls
cluster ctl dumpling tidb-lightning
[root@localhost components]# pwd
/root/.tiup/components
2.导出数据库
我这里导出db_test这个数据库
/root/.tiup/components/dumpling/v6.0.0/dumpling -u root -p mysql -P 4000 -h 192.168.1.118 -B db_test --filetype sql -o /tmp/db_test
3.尝试把导出的数据库删除掉
mysql> drop database db_test;
Query OK, 0 rows affected (1.10 sec)
4.配置
vi /tmp/tidb-lightning.toml
内容如下:
[lightning]
# 日志
level = "info"
file = "tidb-lightning.log"
[tikv-importer]
# 选择使用的 local 后端
backend = "local"
# 设置排序的键值对的临时存放地址,目标路径需要是一个空目录
sorted-kv-dir = "/tmp/sorted-kv-dir"
[mydumper]
# 源数据目录。
data-source-dir = "/tmp/db_test/"
# 配置通配符规则,默认规则会过滤 mysql、sys、INFORMATION_SCHEMA、PERFORMANCE_SCHEMA、METRICS_SCHEMA、INSPECTION_SCHEMA 系统数据库下的所有表
# 若不配置该项,导入系统表时会出现“找不到 schema”的异常
filter = ['*.*', '!mysql.*', '!sys.*', '!INFORMATION_SCHEMA.*', '!PERFORMANCE_SCHEMA.*', '!METRICS_SCHEMA.*', '!INSPECTION_SCHEMA.*']
[tidb]
# 目标集群的信息
host = "192.168.1.118"
port = 4000
user = "root"
password = "mysql"
# 表架构信息在从 TiDB 的“状态端口”获取。
status-port = 10080
# 集群 pd 的地址,这里只写一个即可
pd-addr = "192.168.1.118:2379"
5.导入
[root@localhost v6.0.0]# /root/.tiup/components/tidb-lightning/v6.0.0/tidb-lightning -config /tmp/tidb-lightning.toml
Verbose debug logs will be written to tidb-lightning.log
+---+----------------------------------------------+-------------+--------+
| # | CHECK ITEM | TYPE | PASSED |
+---+----------------------------------------------+-------------+--------+
| 1 | Source csv files size is proper | performance | true |
+---+----------------------------------------------+-------------+--------+
| 2 | checkpoints are valid | critical | true |
+---+----------------------------------------------+-------------+--------+
| 3 | table schemas are valid | critical | true |
+---+----------------------------------------------+-------------+--------+
| 4 | Cluster is available | critical | true |
+---+----------------------------------------------+-------------+--------+
| 5 | Lightning has the correct storage permission | critical | true |
+---+----------------------------------------------+-------------+--------+
tidb lightning exit successfully
6.检查导入的数据
[root@localhost ~]# /opt/mysql5727/bin/mysql -h 192.168.1.134 -P4000 -uroot -p
mysql> use db_test;
mysql> show tables;
+-------------------+
| Tables_in_db_test |
+-------------------+
| tb_t1 |
| tb_test |
+-------------------+
2 rows in set (0.00 sec)
mysql> select count(1) from tb_test;
+----------+
| count(1) |
+----------+
| 1000000 |
+----------+
1 row in set (0.63 sec)