Help Center> Relational Database Service> Troubleshooting> Commands for Exporting Data Through Mysqldump

Commands for Exporting Data Through Mysqldump

Background

Mysqldump is the most commonly used tool for importing and exporting MySQL data. The following are several common application scenarios.

Mysqldump Parameter Description

Table 1

Parameter

Description

add-drop-table

Adds the drop database table statement before each data table is created.

events, E

Exports events.

routines, R

Stores procedures and customized functions.

flush-logs

Updates logs before the logs export.

no-create-db, n

Exports only data without adding of the CREATE DATABASE statement.

add-drop-database

Adds the drop database statement before each database is created.

no-create-info, t

Exports only data without adding of the CREATE TABLE statement.

No-data, d

Exports only the database table structure.

set-gtid-purged=OFF

Does not export gtid statements.

hex-blob

Export binary string fields in hexadecimal format.

Scenarios

Examples are as follows:

  1. Export all data of databases db1 and db2.

    mysqldump -uroot -p -P8635 -h192.168.0.199 --hex-blob --set-gtid-purged=OFF --single-transaction --order-by-primary --flush-logs -q --databases db1 db2 >db12.sql

  2. Export the t1 and t2 tables of the db1 database.

    mysqldump -uroot -p -P8635 -h192.168.0.199 --hex-blob --set-gtid-purged=OFF --single-transaction --order-by-primary --flush-logs -q --databases db1 --tables t1 t2 >t1_t2.sql

  3. Export data whose id equals 1 from table t1 in database db1.

    mysqldump -uroot -p -P8635 -h192.168.0.199 --hex-blob --set-gtid-purged=OFF --single-transaction --order-by-primary --flush-logs -q --databases db1 --tables t1 --where='id=1'>t1_id.sql

  4. Export all table structures in database db1 without exporting data.

    mysqldump -uroot -p -P8635 -h192.168.0.199 --no-data --set-gtid-purged=OFF --single-transaction --order-by-primary -n --flush-logs -q --databases db1 >db1_table.sql

  5. Export all data excluding the tables and data in database db1.

    mysqldump -uroot -p -h192.168.0.199 -P8635 --set-gtid-purged=OFF -F -n -t -d -E -R db1> others.sql