SoFunction
Updated on 2025-04-08

Detailed description and usage of mysqldump parameters

Detailed description of mysqldump parameters

​mysqldump​​ is a powerful tool for exporting data from a MySQL database. It supports a variety of output formats, including​CSV​​、​​SQL​​、​​XML​​ etc. In this article, we will introduce in detail​mysqldump​Some common parameters of ​ and their uses.

Basic use

First, let's take a look at​mysqldump​Basic usage method:

mysqldump [options] database [tables]

Here ​​options​​ is an optional parameter,​database​​ is the database name,​tables​​ is an optional list of table names. If not specified​tables​​,​​mysqldump​​ All tables in the entire database will be exported.

Parameter description

Here are some commonly used ones​mysqldump​Parameters:

-h, --host=name
Specifies the host name or IP address of the MySQL server.
-P, --port=port
Specifies the port of the MySQL server.
-u, --user=name
Specifies the user name to connect to the MySQL server.
-p, --password[=password]
Specifies the password to connect to the MySQL server. If the password is empty, prompt for input.
-d, --no-data
Do not export data, only structures.
-t, --no-create-info
The structure is not exported, only the data is exported.
-c, --comments
Includes comments when exporting.
-q, --quick
Fast mode, send only one query to the server at a time.
-e, --extended-insert
Use extended inserts (plural fields are inserted together).
-r, --order-by-primary
Export data in the order of primary keys.
-f, --force
Force export, even if some errors occur.
-F, --first-name-only
Only table and column names are exported, and data is not exported.
-n, --no-create-db
No database is created.
-T, --target-dir=dir
Specifies the directory where the data is exported.
-A, --all-databases
Export all databases.
--single-transaction
Execute a transaction to ensure that the exported data is consistent.
--set-gtid-purged
Setting the GTID is cleared, which may be useful for some replication scenarios.
--triggers
Export the trigger.
--routines
Export stored procedures and functions.
--events
Export events.
--lock-tables
Lock the exported table to prevent data inconsistency.
--no-lock-tables
Do not lock the exported table.
--add-drop-table
Add a DROP TABLE statement before exporting each table.
--add-locks
Add a syntax for table locking.
--create-options
Export table creation options.
--extended-insert
Use extended inserts (plural fields are inserted together).
--insert-ignore
Use the ​​INSERT IGNORE​ syntax to ignore duplicate records.
--lock-tables
Lock the exported table to prevent data inconsistency.
--no-lock-tables
Do not lock the exported table.
--set-charset
Sets the character set for exporting data.
--default-character-set
Sets the default character set for exporting data.
--hex-blob
Export the BLOB and TEXT fields in hexadecimal format.
--set-gtid-purged
Setting the GTID is cleared, which may be useful for some replication scenarios.
--tz-utc
Convert timestamps to UTC.
--tz-local
Convert timestamps to local time zone.
--help
Show help information.
--version
Display version information.

Example

Here is a simple one​mysqldump​​ Examples:

mysqldump -h localhost -In practical application,mysqldump Commands can be used in multiple scenarios,For example, data backup、Data migration、Data recovery, etc.。The following is a practical application scenariomysqldumpParameter detailed description sample code:
```bash
#!/bin/bash
#  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  It is not a programming language and has no code.mysqldump Parameter details are usually listedmysqldump Various options and parameters that can be accepted by the command,These options and parameters control the behavior of the dump process。For example,You can usemysqldumpTo dump the entire database、A specific table or aSQLQuery results。You can also control the format of the dump file、Whether to include an index、Whether to lock the table、Whether to compress dump files, etc.。
If you need to knowmysqldumpDetailed description of parameters,You can check it outMySQLIn the official documentationmysqldumppart,Or check it by running the following commandmysqldumpHelp information:
```bash
mysqldump --help

This will give you a list of all the available options and parameters for the mysqldump command, as well as their descriptions.

If you are looking for an actual code example instead of the parameter description of mysqldump, you can provide more context information, such as which programming language you are using, or the specific tasks you want to implement, so I can provide you with the corresponding code example.

This is the end of this article about the detailed description of mysqldump parameters. For more detailed description of mysqldump parameters, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!