1.删除数据
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| my_test1 |
| my_test2 |
+----------------+
2 rows in set (0.00 sec)
mysql> drop table my_test1;
Query OK, 0 rows affected (0.52 sec)
mysql> drop table my_test2;
Query OK, 0 rows affected (0.52 sec)
mysql> show tables;
Empty set (0.00 sec)
2.使用tidb-lighting 的local 模式导入
[tidb@mysql1 backup]$ cat tidb-lightning.toml |grep -v ^#
[lightning]
level = "info"
file = "tidb-lightning.log"
max-size = 128 # MB
max-days = 28
max-backups = 14
check-requirements = true
[mydumper]
data-source-dir = "/tidb/backup/"
[tikv-importer]
backend = "local"
sorted-kv-dir="/tidb/tidb-data/tikv-20160"
[tidb]
host = "192.168.1.11"
port = 4000
user = "root"
password = "rootroot"
log-level = "error"
status-port=10080
pd-addr = "192.168.1.11:2379"
--数据目录:
[tidb@mysql1 tikv-20160]$ pwd
/tidb/tidb-data/tikv-20160
[tidb@mysql1 tikv-20160]$ ll
total 5252928
drwxr-xr-x 2 tidb tidb 4096 Aug 17 19:46 db
drwxr-xr-x 4 tidb tidb 33 Aug 17 19:46 import
-rw-r--r-- 1 tidb tidb 17379 Aug 16 16:56 last_tikv.toml
-rw-r--r-- 1 tidb tidb 0 Aug 17 18:03 LOCK
drwxr-xr-x 2 tidb tidb 206 Aug 17 18:03 raft
-rw-r--r-- 1 tidb tidb 449285 Aug 17 19:43 raftdb.info
-rw-r--r-- 1 tidb tidb 2665338 Aug 17 16:57 raftdb.info.2024-08-17-16:57:25.003290017
-rw-r--r-- 1 tidb tidb 1072685 Aug 17 19:46 rocksdb.info
-rw-r--r-- 1 tidb tidb 5821790 Aug 17 16:57 rocksdb.info.2024-08-17-16:57:25.357407034
drwxr-xr-x 2 tidb tidb 6 Aug 16 16:57 snap
-rw-r--r-- 1 tidb tidb 5368709120 Aug 16 16:56 space_placeholder_file
--导入数据
[tidb@mysql1 backup]$ tidb-lightning -config tidb-lightning.toml
Verbose debug logs will be written to tidb-lightning.log
[2024/08/17 19:46:19.779 +08:00] [INFO] [client.go:148] ["[pd] create pd client with endpoints"] [pd-address="[192.168.1.11:2379]"]
[2024/08/17 19:46:19.783 +08:00] [INFO] [base_client.go:237] ["[pd] update member urls"] [old-urls="[http://192.168.1.11:2379]"] [new-urls="[http://192.168.1.11:2379,http://192.168.1.12:2379,http://192.168.1.13:2379]"]
[2024/08/17 19:46:19.783 +08:00] [INFO] [base_client.go:253] ["[pd] switch leader"] [new-leader=http://192.168.1.13:2379] [old-leader=]
[2024/08/17 19:46:19.783 +08:00] [INFO] [base_client.go:103] ["[pd] init cluster id"] [cluster-id=7403658561768514175]
tidb lightning exit
3.数据检查
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| my_test1 |
| my_test2 |
+----------------+
2 rows in set (0.00 sec)
mysql> select * from my_test1;
+------+------+
| id | name |
+------+------+
| 1 | xsq1 |
| 2 | xsq2 |
| 3 | xsq3 |
| 4 | xsq4 |
+------+------+
4 rows in set (0.02 sec)
mysql> select * from my_test2;
+------+-------------+
| id | name |
+------+-------------+
| 1 | 薛双奇1 |
| 2 | 薛双奇2 |
| 3 | 薛双奇3 |
| 4 | 薛双奇4 |
| 5 | 薛双奇5 |
| 6 | 薛双奇6 |
| 7 | 薛双奇7 |
| 8 | 薛双奇8 |
| 9 | 薛双奇9 |
| 10 | 薛双奇10 |
+------+-------------+
10 rows in set (0.01 sec)
4.总结
tidb-lighting的两种导入模式,tidb 模式是导入mydumper导出的SQL文件,
直接连接TIDB进行导入。
local模式:连接数据数据库直接导入:tikv 的目录中。’