Importing Data into TiDB

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TiDB 导入数据

| username: TiDBer_djgos04V

Is there any way to let TiDB import SQL scripts that are not exported by dumpling, similar to SQL scripts exported by Navicat?

| username: tidb菜鸟一只 | Original post link

Isn’t an SQL script supposed to be executed directly?

| username: TiDBer_djgos04V | Original post link

Scripts containing data have a relatively large magnitude, and I hope there are methods to improve the speed.

| username: 啦啦啦啦啦 | Original post link

The SQL exported by Navicat can only be imported in a single thread, and using Navicat for export indicates that the data volume is not too large. If you want to speed up, it’s better to use Dumpling or BR.

| username: TiDBer_djgos04V | Original post link

The SQL script provided upstream is over 20GB and will be even larger in the future. Currently, it is also not possible to use Dumpling to access the source database, so there is no solution.

| username: h5n1 | Original post link

Manually split into multiple files, then name the files according to the lightning format.

| username: tidb菜鸟一只 | Original post link

In that case, you probably need to write a script to split the SQL file into meta files and SQL files like those exported by Dumpling. Otherwise, with just one file, you can’t parallelize the process…

| username: TiDBer_djgos04V | Original post link

Alright, thank you everyone.

| username: cassblanca | Original post link

Is this 20G SQL insert script for stress testing TiDB? :smile: You can split the file into multiple parts and import them into different tables, then merge the data from multiple tables together. Using partitioned tables is also an option.

| username: redgame | Original post link

Use lightning.

| username: 像风一样的男子 | Original post link

Can the data format exported from upstream be changed to CSV? Lightning supports importing CSV files.

| username: zhanggame1 | Original post link

Using Navicat to export as CSV is faster than SQL. Just create the table in advance, then import it with Lightning.

| username: 啦啦啦啦啦 | Original post link

:rofl: The person providing the upstream data is quite something. Importing 20GB with Navicat to a local machine would be extremely slow. It’s better to solve the issue at the source, whether by splitting the SQL file or something else, as both are quite troublesome. Alternatively, exporting to CSV with Navicat is also an option, but exporting will definitely be much slower than using Dumpling.

| username: zhanggame1 | Original post link

Navicat exporting 20G to local isn’t that slow. In my test, exporting to my own laptop was about 100,000 rows per second, and it took less than 10 minutes for a single table of 1G. Navicat can open multiple windows for concurrent operations, which speeds things up significantly. With two windows open, it can take less than 5 minutes for 1G.

| username: 啦啦啦啦啦 | Original post link

:rofl: Isn’t this still slow?

| username: zhanggame1 | Original post link

Find a tool to export CSV by yourself, it should be faster.

| username: 像风一样的男子 | Original post link

Why not use mysqldump on the server to export? Isn’t it faster?