Detailed explanation of MySQLdump parameters

parameter

Parameter Description

–all-databases , -A

Export all databases.

mysqldump -uroot -p --all-databases

–all-tablespaces , -Y

Export all table spaces.

mysqldump -uroot -p --all-databases --all-tablespaces

–No-tablespaces, -y

Do not export any table space information.

mysqldump -uroot -p --all-databases --no-tablespaces

–add-drop-database

Add the drop database statement before each database is created.

mysqldump -uroot -p --all-databases --add-drop-database

–add-drop-table

Add the drop data table statement before each data table is created. (The default is open, use -skip-add-drop-table to cancel the option)

mysqldump -uroot -p --all-databases (add the drop statement by default)

mysqldump -uroot -p --all-databases --skip-add-drop-table (cancel the drop statement)

–add-locks

Increase LOCK TABLES before exporting each table and UNLOCK TABLE afterwards. (The default is open, use -skip-add-locks to cancel the option)

mysqldump -uroot -p --all-databases (LOCK statement is added by default)

mysqldump -uroot -p --all-databases --skip-add-locks (cancel the LOCK statement)

–allow-keywords

It is allowed to create column names that are keywords. This is done by prefixing the table name to each column name.

mysqldump -uroot -p --all-databases --allow-keywords

–apply-slave-statements

Add'STOP SLAVE' before'CHANGE MASTER', and add'START SLAVE' at the end of the export.

mysqldump -uroot -p --all-databases --apply-slave-statements

–character-sets-dir

Character set file directory

mysqldump -uroot -p --all-databases --character-sets-dir=/usr/local/mysql/share/mysql/charsets

–comments

Additional annotation information. The default is open, you can cancel with –skip-comments

mysqldump -uroot -p --all-databases (default record comment)

mysqldump -uroot -p --all-databases --skip-comments (uncomment)

–compatible

The exported data will be compatible with other databases or old versions of MySQL. The value can be ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_tables_options, no_field_options, etc.,

To use several values, separate them with commas. It is not guaranteed to be fully compatible, but as compatible as possible.

mysqldump -uroot -p --all-databases --compatible=ansi

–compact

Export less output information (for debugging). Remove the comment and head and tail structure. You can use options: --skip-add-drop-table --skip-add-locks --skip-comments --skip-disable-keys

mysqldump -uroot -p --all-databases --compact

–complete-insert, -c

Use the complete insert statement (including column names). Doing so can improve the insertion efficiency, but may be affected by the max_allowed_packet parameter and cause the insertion to fail.

mysqldump -uroot -p --all-databases --complete-insert

–compress, -C

Enable compression to pass all information between client and server

mysqldump -uroot -p --all-databases --compress

–create-options, -a

Include all MySQL feature options in the CREATE TABLE statement. (Default is on)

mysqldump -uroot -p --all-databases

–databases, -B

Export several databases. All name parameters after the parameters are regarded as database names.

mysqldump -uroot -p --databases test mysql

–debug

Output debug information for debugging. The default value is: d:t:o,/tmp/mysqldump.trace

mysqldump -uroot -p --all-databases --debug

mysqldump -uroot -p --all-databases --debug=” d:t:o,/tmp/debug.trace”

–debug-check

Check the memory and open file instructions and exit.

mysqldump -uroot -p --all-databases --debug-check

–debug-info

Output debugging information and exit

mysqldump -uroot -p --all-databases --debug-info

–default-character-set

Set the default character set, the default value is utf8

mysqldump -uroot -p --all-databases --default-character-set=latin1

–delayed-insert

Export data using INSERT DELAYED

mysqldump -uroot -p --all-databases --delayed-insert

–delete-master-logs

Delete the log after the master backup. This parameter will be automatically activated -master-data.

mysqldump -uroot -p --all-databases --delete-master-logs

–disable-keys

For each table, use the /*!40000 ALTER TABLE tbl_name DISABLE KEYS /; and / !40000 ALTER TABLE tbl_name ENABLE KEYS */; statements to reference the INSERT statement. This can import the dumped file faster because it creates an index after inserting all rows. This option is only suitable for MyISAM tables and is turned on by default.

mysqldump -uroot -p --all-databases

–dump-slave

This option will cause the main binlog location and file name to be appended to the exported data file. When it is set to 1, it will be output to the data file with the CHANGE MASTER command; when it is set to 2, the explanation information is added before the command. This option will turn on –lock-all-tables unless –single-transaction is specified. This option will automatically turn off the -lock-tables option. The default value is 0.

mysqldump -uroot -p --all-databases --dump-slave=1

mysqldump -uroot -p --all-databases --dump-slave=2

–events, -E

Export events.

mysqldump -uroot -p --all-databases --events

–extended-insert, -e

Use INSERT syntax with multiple VALUES columns. This makes the export file smaller and speeds up the import speed. The default is on, use -skip-extended-insert to cancel the option.

mysqldump -uroot -p --all-databases

mysqldump -uroot -p --all-databases--skip-extended-insert (cancel option)

–fields-terminated-by

The given field is ignored in the export file. Used with the –tab option, cannot be used with the –databases and –all-databases options

mysqldump -uroot -p test test --tab=”/home/mysql” --fields-terminated-by=”#”

–fields-enclosed-by

Each field in the output file is wrapped with given characters. Used with the –tab option, cannot be used with the –databases and –all-databases options

mysqldump -uroot -p test test --tab=”/home/mysql” --fields-enclosed-by=”#”

–fields-optionally-enclosed-by

Each field in the output file is selectively wrapped with given characters. Used with the –tab option, cannot be used with the –databases and –all-databases options

mysqldump -uroot -p test test --tab=”/home/mysql” --fields-enclosed-by=”#” --fields-optionally-enclosed-by =”#”

–fields-escaped-by

Each field in the output file ignores the given characters. Used with the –tab option, cannot be used with the –databases and –all-databases options

mysqldump -uroot -p mysql user --tab=”/home/mysql” --fields-escaped-by=”#”

–flush-logs

Refresh the log before starting the export.

Please note: If you export multiple databases at once (using the option –databases or –all-databases), the log will be refreshed one by one. In addition to using --lock-all-tables or --master-data. In this case, the log will be refreshed once, and the corresponding tables will be locked at the same time. Therefore, if you plan to export and flush logs at the same time, you should use –lock-all-tables or –master-data and –flush-logs.

mysqldump -uroot -p --all-databases --flush-logs

–flush-privileges

After exporting the mysql database, issue a FLUSH PRIVILEGES statement. In order to recover correctly, this option should be used at any time when exporting mysql database and relying on mysql database data.

mysqldump -uroot -p --all-databases --flush-privileges

–force

Ignore SQL errors that appear during the export process.

mysqldump -uroot -p --all-databases --force

–help

Display help information and exit.

mysqldump --help

–hex-blob

Export binary string fields in hexadecimal format. You must use this option if you have binary data. The affected field types are BINARY, VARBINARY, and BLOB.

mysqldump -uroot -p --all-databases --hex-blob

–host, -h

Host information to be exported

mysqldump -uroot -p --host=localhost --all-databases

–ignore-table

Do not export the specified table. When specifying to ignore multiple tables, it needs to be repeated multiple times, one table at a time. Each table must specify the database and table name at the same time. For example: --ignore-table=database.table1 --ignore-table=database.table2 ……

mysqldump -uroot -p --host=localhost --all-databases --ignore-table=mysql.user

–include-master-host-port

Add'MASTER_HOST=, MASTER_PORT=' to the'CHANGE MASTER TO...' statement generated by -dump-slave

mysqldump -uroot -p --host=localhost --all-databases --include-master-host-port

–insert-ignore

Use the INSERT IGNORE statement when inserting rows.

mysqldump -uroot -p --host=localhost --all-databases --insert-ignore

–lines-terminated-by

Each line of the output file is divided by a given string. Used with the –tab option, it cannot be used with the –databases and –all-databases options.

mysqldump -uroot -p --host=localhost test test --tab=”/tmp/mysql” --lines-terminated-by=”##”

–lock-all-tables, -x

Submit a request to lock all tables in all databases to ensure data consistency. This is a global read lock, and the –single-transaction and –lock-tables options are automatically closed.

mysqldump -uroot -p --host=localhost --all-databases --lock-all-tables

–lock-tables, -l

Before starting the export, lock all tables. Lock the table with READ LOCAL to allow parallel inserts into MyISAM tables. For tables that support transactions, such as InnoDB and BDB, -single-transaction is a better choice because it does not need to lock the table at all.

Please note that when exporting multiple databases, --lock-tables locks the tables for each database separately. Therefore, this option cannot guarantee the logical consistency of the tables in the export file between databases. The export status of different database tables can be completely different.

mysqldump -uroot -p --host=localhost --all-databases --lock-tables

–log-error

Append warning and error messages to the given file

mysqldump -uroot -p --host=localhost --all-databases --log-error=/tmp/mysqldump_error_log.err

–master-data

This option appends the location and file name of binlog to the output file. If it is 1, it will output the CHANGE MASTER command; if it is 2, add a comment before the output CHANGE MASTER command. This option will turn on the –lock-all-tables option, unless –single-transaction is also specified (in this case, the global read lock is obtained for a short time when the export starts; for other content, refer to the –single-transaction option below ). This option automatically turns off the -lock-tables option.

mysqldump -uroot -p --host=localhost --all-databases --master-data=1;

mysqldump -uroot -p --host=localhost --all-databases --master-data=2;

–max_allowed_packet

The maximum packet length sent and received by the server.

mysqldump -uroot -p --host=localhost --all-databases --max_allowed_packet=10240

–net_buffer_length

Cache size of TCP/IP and socket connections.

mysqldump -uroot -p --host=localhost --all-databases --net_buffer_length=1024

–no-autocommit

Use the autocommit/commit statement to wrap the table.

mysqldump -uroot -p --host=localhost --all-databases --no-autocommit

–no-create-db, -n

Only export data without adding CREATE DATABASE statement.

mysqldump -uroot -p --host=localhost --all-databases --no-create-db

–no-create-info, -t

Only export data without adding CREATE TABLE statement.

mysqldump -uroot -p --host=localhost --all-databases --no-create-info

–no-data, -d

Does not export any data, only the database table structure.

mysqldump -uroot -p --host=localhost --all-databases --no-data

–no-set-names, -N

Equivalent to --skip-set-charset

mysqldump -uroot -p --host=localhost --all-databases --no-set-names

–opt

Equivalent to --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, --disable-keys this option It is enabled by default, and can be disabled with --skip-opt.

mysqldump -uroot -p --host=localhost --all-databases --opt

–order-by-primary

If there is a primary key, or the first unique key, sort the records of each table. It is effective when exporting MyISAM tables to InnoDB tables, but it will take a long time to export.

mysqldump -uroot -p --host=localhost --all-databases --order-by-primary

–password, -p

Database connection password

--Pipe (available on windows system)

Use named pipes to connect to mysql

mysqldump -uroot -p --host=localhost --all-databases --pipe

–port, -P

Connect to the database port number

–protocol

The connection protocol used, including: tcp, socket, pipe, memory.

mysqldump -uroot -p --host=localhost --all-databases --protocol=tcp

–quick, -q

The query is not buffered and directly exported to standard output. The default is on, use -skip-quick to cancel this option.

mysqldump -uroot -p --host=localhost --all-databases

mysqldump -uroot -p --host=localhost --all-databases --skip-quick

--quote-names,-Q

Use (`) to cause table and column names. The default is on, use -skip-quote-names to cancel this option.

mysqldump -uroot -p --host=localhost --all-databases

mysqldump -uroot -p --host=localhost --all-databases --skip-quote-names

–replace

Use REPLACE INTO instead of INSERT INTO.

mysqldump -uroot -p --host=localhost --all-databases --replace

–result-file, -r

Direct output to the specified file. This option should be used on systems that use the carriage return line feed (\r\n) line feed (for example: DOS, Windows). This option ensures that only one line is used.

mysqldump -uroot -p --host=localhost --all-databases --result-file=/tmp/mysqldump_result_file.txt

–routines, -R

Export stored procedures and custom functions.

mysqldump -uroot -p --host=localhost --all-databases --routines

–set-charset

Add'SET NAMES default_character_set' to the output file. The default is on, use -skip-set-charset to close the option.

mysqldump -uroot -p --host=localhost --all-databases

mysqldump -uroot -p --host=localhost --all-databases --skip-set-charset

–single-transaction

This option submits a BEGIN SQL statement before exporting the data. BEGIN will not block any application and can guarantee the consistency of the database when exporting. It only applies to multi-version storage engines, only InnoDB. This option and the -lock-tables option are mutually exclusive, because LOCK TABLES will implicitly commit any pending transactions. If you want to export a large table, you should use the -quick option in combination.

mysqldump -uroot -p --host=localhost --all-databases --single-transaction

–dump-date

Add the export time to the output file. The default is on, use -skip-dump-date to close the option.

mysqldump -uroot -p --host=localhost --all-databases

mysqldump -uroot -p --host=localhost --all-databases --skip-dump-date

–skip-opt

Disable the --opt option.

mysqldump -uroot -p --host=localhost --all-databases --skip-opt

–socket,-S

Specify the socket file location for connecting to mysql, the default path /tmp/mysql.sock

mysqldump -uroot -p --host=localhost --all-databases --socket=/tmp/mysqld.sock

–tab,-T

Create a tab-divided text file at the given path for each table. Note: Only used for mysqldump and mysqld server running on the same machine.

mysqldump -uroot -p --host=localhost test test --tab="/home/mysql"

–tables

Override the -databases (-B) parameter to specify the name of the table to be exported.

mysqldump -uroot -p --host=localhost --databases test --tables test

–triggers

Export triggers. This option is enabled by default, use –skip-triggers to disable it.

mysqldump -uroot -p --host=localhost --all-databases --triggers

–tz-utc

Set the time zone TIME_ZONE='+00:00' at the top of the export to ensure the correctness of the TIMESTAMP data exported in a different time zone or when the data is moved to another time zone.

mysqldump -uroot -p --host=localhost --all-databases --tz-utc

–user, -u

Specify the user name of the connection.

–verbose, --v

Output various platform information.

–version, -V

Output mysqldump version information and exit

–where, -w

Only dump the records selected by the given WHERE condition. Please note that if the condition contains spaces or characters dedicated to the command interpreter, be sure to quote the condition.

mysqldump -uroot -p --host=localhost --all-databases --where=” user=’root’”

–Xml, -X

Export to XML format.

mysqldump -uroot -p --host=localhost --all-databases --xml

–Plugin_dir

A directory of client plug-ins, used to be compatible with different plug-in versions.

mysqldump -uroot -p --host=localhost --all-databases --plugin_dir=”/usr/local/lib/plugin”

–default_auth

The client plug-in uses default permissions.

mysqldump -uroot -p --host=localhost --all-databases --default-auth=”/usr/local/lib/plugin/< PLUGIN >”

Option file, remember: you can control the behavior of the program completely on the command line without relying on the option file

The program reads the standard configuration file path sequence: C:\WINDOWS\my.ini C:\WINDOWS\my.cnf C:\my.ini C:\my.cnf D:\Program Files\MySQL\MySQL Server 5.1 master \my.ini D:\Program Files\MySQL\MySQL Server 5.1 master\my.cnf: Default setting options: [mysqldump] and [client] section configuration options.

This behavior can be changed by the first option of the standard mysql program:

--Print-defaults Print the program argument list and exit-Print out the default configuration options of the program, and immediately exit the execution of the program. Used to understand the default option configuration
-no-defaults Don't read default options from any options file-Do not read any default options configuration file configuration, you need to provide command line options on the command line. For clean control configuration options, it must be configured with command line options
–defaults-file=# Only read default options from the given file # – Do not read any configuration under the default option configuration file, only read the specified option configuration file . Used for clean control configuration options
–defaults-extra-file=# Read this file after the global files are read – Read the configuration under any default option configuration file, and then read the specified option configuration file. Used to supplement or replace the deficiency of the default configuration!

Common configuration options

The values ​​of these characteristic variables can be changed by setting the configuration options

note:

–opt = --add-drop-table、–add-locks、–create-options、–quick、–extented-insert、–lock-tables、–set-charset、–disable-keys
–skip-opt

Configuration options related to database objects:

–databases
–all-databases
–all-tablespaces
–no-tablespaces
–events
–routines
–triggers
–tables 可以屏蔽–databases选项
–ignore-table=name

Configuration options related to script format:

–all
–create-options #相当于–all
–replace
–complete-insert
–extented-insert
–delayed-insert
–disable-keys
–no-create-db
–add-drop-database
–no-create-info
–add-drop-table
–quote-name
–no-autocommit
–skip-set-charset #相当于–no-set-names
–set-charset
–tz-utc
–dump-date
–xml

Options related to the number of data rows:

–no-data
–where=name
–order-by-primary

Configuration options related to data type and encoding:

–default-character-set
–hex-blob

Configuration options related to data integrity:

–lock-tables
–lock-all-tables
–single-transaction

Configuration options related to export performance:

–quick
–order-by-primary
–default-character-set
–delayed-insert
–disable-keys
–no-autocommit
–net-buffer-length=#
–max-allowed-packet=#

Configuration options related to error control:

–force
–log-error=name

Configuration options related to files:

–log-error=name
–result-file=name

Error handling

unknown option '--no-beep' 

The first method: delete the no-beep parameter under my.ini[client]; the
second method: add the –no-defaults parameter after mysqldump.

Guess you like

Origin blog.csdn.net/weixin_46152207/article/details/113307860