Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: tiup dumpling 如何导出试图
[TiDB Usage Environment] Production Environment
[TiDB Version] 5.2.2
[Reproduction Path]
When exporting TiDB views using the mysqldump command, some TiDB information is included. I want to use the tiup dumpling command to export the view and then import the view into MySQL.
Database: thc_1000_abc
View name: v_abcd
Export command:
tiup dumpling
–user root
–password aabbccdd
–host 192.168.1.2
–port 4000
–no-data
–tables-list thc_1000_abc.v_abcd
–database thc_1000_abc
–output thc_1000_abc/
[Encountered Problem: Problem Phenomenon and Impact]
After exporting, only the metadata and thc_1000_abc-schema-create.sql tables are present, but there is no view SQL. However, exporting non-view tables using this command works fine.
Is there an issue with the command I used?
-W, --no-views Do not dump views (default true) According to the new version of dumpling help, the default is to back up. You can try upgrading the dumpling version.
The TiUP Dumpling tool can export table data from TiDB, but it currently does not support exporting views. If you need to export views, you can use the official MySQL mysqldump tool or the TiDB Lightning tool provided by TiDB.
If you use the mysqldump command to export TiDB views, it may include some TiDB-specific information, such as TiDB’s transaction IDs. If you need to import the views into MySQL, it is recommended to use the TiDB Lightning tool, which can export data from TiDB in a MySQL-compatible format, including view data. The specific steps are as follows:
-
Install the TiDB Lightning tool:
tiup install tidb-lightning
-
Configure the TiDB Lightning tool:
Example configuration file:
[lightning]
# Path to the lightning log file
log-file = "/path/to/lightning.log"
# Path to the lightning progress file
progress-file = "/path/to/lightning.progress"
# Path to the lightning configuration file
config-file = "/path/to/lightning.toml"
[tidb]
# TiDB address
host = "127.0.0.1"
# TiDB port number
port = 4000
# TiDB username
user = "root"
# TiDB password
password = ""
[mydumper]
# Path to the mydumper export files
data-source-dir = "/path/to/mydumper"
# Number of mydumper threads
threads = 16
[myloader]
# Path to the myloader import files
data-source-dir = "/path/to/myloader"
# Number of myloader threads
threads = 16
The [tidb]
section contains the TiDB connection information, the [mydumper]
section contains the export data configuration, and the [myloader]
section contains the import data configuration.
-
Export TiDB data:
Use the TiDB Lightning tool to export TiDB data, including view data:
tiup tidb-lightning \
--config /path/to/lightning.toml \
--tidb-host 127.0.0.1 \
--tidb-port 4000 \
--tidb-user root \
--tidb-password "" \
--backend local \
--enable-checkpoint=false \
--log-file /path/to/lightning.log \
--progress-file /path/to/lightning.progress
Here, --backend local
indicates exporting data to a local file, --enable-checkpoint=false
indicates not enabling checkpoints, and --log-file
and --progress-file
specify the paths to the log file and progress file, respectively.
-
Import MySQL data:
Import the exported data into MySQL, including view data:
tiup tidb-lightning \
--config /path/to/lightning.toml \
--backend local \
--mydumper-data-dir /path/to/mydumper \
--myloader-data-dir /path/to/myloader \
--log-file /path/to/lightning.log \
--progress-file /path/to/lightning.progress
Here, --backend local
indicates importing data from a local file, and --mydumper-data-dir
and --myloader-data-dir
specify the paths to the export and import data, respectively.
Thanks, I’ll give it a try.
You misunderstood, the default is not to back up, backing up is false
-W=false
Thank you very much, I will give it a try.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.