mysqldump 参数命令详解

来源:互联网 发布:苹果换铃声软件 编辑:程序博客网 时间:2024/05/23 15:39
mysqldump --help 
mysqldump  Ver 10.13 Distrib 5.6.32-78.1, for Linux (x86_64)
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Dumping structure and contents of MySQL databases and tables.
Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]


Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /mnt/workspace/percona-xtradb-cluster-5.6-binary-new/label_exp/centos6-64/Percona-XtraDB-Cluster-5.6.32-78.1/75/usr/local/Percona-XtraDB-Cluster-5.6.32-rel78.1-25.17.1.Linux.x86_64.ssl101/etc/my.cnf ~/.my.cnf 
The following groups are read: mysqldump client
The following options may be given as the first argument:
--print-defaults        Print the program argument list and exit.
--no-defaults           Don't read default options from any option file,
                        except for login file.
--defaults-file=#       Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=#
                        Also read groups with concat(group, suffix)
--login-path=#          Read this path from the login file.
  -A, --all-databases Dump all the databases. This will be same as --databases
                      with all databases selected.
  -Y, --all-tablespaces 
                      Dump all the tablespaces.
  -y, --no-tablespaces 
                      Do not dump any tablespace information.
  --add-drop-database Add a DROP DATABASE before each create.
  --add-drop-table    Add a DROP TABLE before each create.
                      (Defaults to on; use --skip-add-drop-table to disable.)
  --add-drop-trigger  Add a DROP TRIGGER before each create.
  --add-locks         Add locks around INSERT statements.
                      (Defaults to on; use --skip-add-locks to disable.)
  --allow-keywords    Allow creation of column names that are keywords.
  --apply-slave-statements 
                      Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START
                      SLAVE' to bottom of dump.
  --lock-for-backup   Use lightweight metadata locks to block updates to
                      non-transactional tables and DDL to all tables. This
                      works only with --single-transaction, otherwise this
                      option is automatically converted to --lock-all-tables.
  --bind-address=name IP address to bind to.
  --character-sets-dir=name 
                      Directory for character set files.
  -i, --comments      Write additional information.
                      (Defaults to on; use --skip-comments to disable.)
  --compatible=name   Change the dump to be compatible with a given mode. By
                      default tables are dumped in a format optimized for
                      MySQL. Legal modes are: ansi, mysql323, mysql40,
                      postgresql, oracle, mssql, db2, maxdb, no_key_options,
                      no_table_options, no_field_options. One can use several
                      modes separated by commas. Note: Requires MySQL server
                      version 4.1.0 or higher. This option is ignored with
                      earlier server versions.
  --compact           Give less verbose output (useful for debugging). Disables
                      structure comments and header/footer constructs.  Enables
                      options --skip-add-drop-table --skip-add-locks
                      --skip-comments --skip-disable-keys --skip-set-charset.
  -c, --complete-insert 
                      Use complete insert statements.
  -C, --compress      Use compression in server/client protocol.
  -a, --create-options 
                      Include all MySQL specific create options.
                      (Defaults to on; use --skip-create-options to disable.)
  -B, --databases     Dump several databases. Note the difference in usage; in
                      this case no tables are given. All name arguments are
                      regarded as database names. 'USE db_name;' will be
                      included in the output.
  -#, --debug[=#]     This is a non-debug version. Catch this and exit.
  --debug-check       Check memory and open file usage at exit.
  --debug-info        Print some debug info at exit.
  --default-character-set=name 
                      Set the default character set.
  --delayed-insert    Insert rows with INSERT DELAYED.
  --delete-master-logs 
                      Delete logs on master after backup. This automatically
                      enables --master-data.
  -K, --disable-keys  '/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and
                      '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put
                      in the output.
                      (Defaults to on; use --skip-disable-keys to disable.)
  --dump-slave[=#]    This causes the binary log position and filename of the
                      master to be appended to the dumped data output. Setting
                      the value to 1, will printit as a CHANGE MASTER command
                      in the dumped data output; if equal to 2, that command
                      will be prefixed with a comment symbol. This option will
                      turn --lock-all-tables on, unless --single-transaction is
                      specified too (in which case a global read lock is only
                      taken a short time at the beginning of the dump - don't
                      forget to read about --single-transaction below). In all
                      cases any action on logs will happen at the exact moment
                      of the dump.Option automatically turns --lock-tables off.
  -E, --events        Dump events.
  -e, --extended-insert 
                      Use multiple-row INSERT syntax that include several
                      VALUES lists.
                      (Defaults to on; use --skip-extended-insert to disable.)
  --fields-terminated-by=name 
                      Fields in the output file are terminated by the given
                      string.
  --fields-enclosed-by=name 
                      Fields in the output file are enclosed by the given
                      character.
  --fields-optionally-enclosed-by=name 
                      Fields in the output file are optionally enclosed by the
                      given character.
  --fields-escaped-by=name 
                      Fields in the output file are escaped by the given
                      character.
  -F, --flush-logs    Flush logs file in server before starting dump. Note that
                      if you dump many databases at once (using the option
                      --databases= or --all-databases), the logs will be
                      flushed for each database dumped. The exception is when
                      using --lock-all-tables or --master-data: in this case
                      the logs will be flushed only once, corresponding to the
                      moment all tables are locked. So if you want your dump
                      and the log flush to happen at the same exact moment you
                      should use --lock-all-tables or --master-data with
                      --flush-logs.
  --flush-privileges  Emit a FLUSH PRIVILEGES statement after dumping the mysql
                      database.  This option should be used any time the dump
                      contains the mysql database and any other database that
                      depends on the data in the mysql database for proper
                      restore. 
  -f, --force         Continue even if we get an SQL error.
  -?, --help          Display this help message and exit.
  --hex-blob          Dump binary strings (BINARY, VARBINARY, BLOB) in
                      hexadecimal format.
  -h, --host=name     Connect to host.
  --ignore-table=name Do not dump the specified table. To specify more than one
                      table to ignore, use the directive multiple times, once
                      for each table.  Each table must be specified with both
                      database and table names, e.g.,
                      --ignore-table=database.table.
  --include-master-host-port 
                      Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE
                      MASTER TO..' in dump produced with --dump-slave.
  --innodb-optimize-keys 
                      Use InnoDB fast index creation by creating secondary
                      indexes after dumping the data.
  --insert-ignore     Insert rows with INSERT IGNORE.
  --ignore-create-error 
                      Don't exit on show create table errors.
  --lines-terminated-by=name 
                      Lines in the output file are terminated by the given
                      string.
  -x, --lock-all-tables 
                      Locks all tables across all databases. This is achieved
                      by taking a global read lock for the duration of the
                      whole dump. Automatically turns --single-transaction and
                      --lock-tables off.
  -l, --lock-tables   Lock all tables for read.
                      (Defaults to on; use --skip-lock-tables to disable.)
  --log-error=name    Append warnings and errors to given file.
  --master-data[=#]   This causes the binary log position and filename to be
                      appended to the output. If equal to 1, will print it as a
                      CHANGE MASTER command; if equal to 2, that command will
                      be prefixed with a comment symbol. This option will turn
                      --lock-all-tables on, unless --single-transaction is
                      specified too (on servers that don't provide
                      Binlog_snapshot_file and Binlog_snapshot_position status
                      variables this will still take a global read lock for a
                      short time at the beginning of the dump; don't forget to
                      read about --single-transaction below). In all cases, any
                      action on logs will happen at the exact moment of the
                      dump. Option automatically turns --lock-tables off.
  --max-allowed-packet=# 
                      The maximum packet length to send to or receive from
                      server.
  --net-buffer-length=# 
                      The buffer size for TCP/IP and socket communication.
  --no-autocommit     Wrap tables with autocommit/commit statements.
  -n, --no-create-db  Suppress the CREATE DATABASE ... IF EXISTS statement that
                      normally is output for each dumped database if
                      --all-databases or --databases is given.
  -t, --no-create-info 
                      Don't write table creation info.
  -d, --no-data       No row information.
  -N, --no-set-names  Same as --skip-set-charset.
  --opt               Same as --add-drop-table, --add-locks, --create-options,
                      --quick, --extended-insert, --lock-tables, --set-charset,
                      and --disable-keys. Enabled by default, disable with
                      --skip-opt.
  --order-by-primary  Sorts each table's rows by primary key, or first unique
                      key, if such a key exists.  Useful when dumping a MyISAM
                      table to be loaded into an InnoDB table, but will make
                      the dump itself take considerably longer.
  -p, --password[=name] 
                      Password to use when connecting to server. If password is
                      not given it's solicited on the tty.
  -P, --port=#        Port number to use for connection.
  --protocol=name     The protocol to use for connection (tcp, socket, pipe,
                      memory).
  -q, --quick         Don't buffer query, dump directly to stdout.
                      (Defaults to on; use --skip-quick to disable.)
  -Q, --quote-names   Quote table and column names with backticks (`).
                      (Defaults to on; use --skip-quote-names to disable.)
  --replace           Use REPLACE INTO instead of INSERT INTO.
  -r, --result-file=name 
                      Direct output to a given file. This option should be used
                      in systems (e.g., DOS, Windows) that use carriage-return
                      linefeed pairs (\r\n) to separate text lines. This option
                      ensures that only a single newline is used.
  -R, --routines      Dump stored routines (functions and procedures).
  --set-charset       Add 'SET NAMES default_character_set' to the output.
                      (Defaults to on; use --skip-set-charset to disable.)
  --set-gtid-purged[=name] 
                      Add 'SET @@GLOBAL.GTID_PURGED' to the output. Possible
                      values for this option are ON, OFF and AUTO. If ON is
                      used and GTIDs are not enabled on the server, an error is
                      generated. If OFF is used, this option does nothing. If
                      AUTO is used and GTIDs are enabled on the server, 'SET
                      @@GLOBAL.GTID_PURGED' is added to the output. If GTIDs
                      are disabled, AUTO does nothing. If no value is supplied
                      then the default (AUTO) value will be considered.
  --single-transaction 
                      Creates a consistent snapshot by dumping all tables in a
                      single transaction. Works ONLY for tables stored in
                      storage engines which support multiversioning (currently
                      only InnoDB does); the dump is NOT guaranteed to be
                      consistent for other storage engines. While a
                      --single-transaction dump is in process, to ensure a
                      valid dump file (correct table contents and binary log
                      position), no other connection should use the following
                      statements: ALTER TABLE, DROP TABLE, RENAME TABLE,
                      TRUNCATE TABLE, as consistent snapshot is not isolated
                      from them. Option automatically turns off --lock-tables.
  --dump-date         Put a dump date to the end of the output.
                      (Defaults to on; use --skip-dump-date to disable.)
  --skip-opt          Disable --opt. Disables --add-drop-table, --add-locks,
                      --create-options, --quick, --extended-insert,
                      --lock-tables, --set-charset, and --disable-keys.
  -S, --socket=name   The socket file to use for connection.
  --secure-auth       Refuse client connecting to server if it uses old
                      (pre-4.1.1) protocol.
                      (Defaults to on; use --skip-secure-auth to disable.)
  --ssl               Enable SSL for connection (automatically enabled with
                      other flags).
  --ssl-ca=name       CA file in PEM format (check OpenSSL docs, implies
                      --ssl).
  --ssl-capath=name   CA directory (check OpenSSL docs, implies --ssl).
  --ssl-cert=name     X509 cert in PEM format (implies --ssl).
  --ssl-cipher=name   SSL cipher to use (implies --ssl).
  --ssl-key=name      X509 key in PEM format (implies --ssl).
  --ssl-crl=name      Certificate revocation list (implies --ssl).
  --ssl-crlpath=name  Certificate revocation list path (implies --ssl).
  --ssl-verify-server-cert 
                      Verify server's "Common Name" in its cert against
                      hostname used when connecting. This option is disabled by
                      default.
  --ssl-mode=name     SSL connection mode.
  -T, --tab=name      Create tab-separated textfile for each table to given
                      path. (Create .sql and .txt files.) NOTE: This only works
                      if mysqldump is run on the same machine as the mysqld
                      server.
  --tables            Overrides option --databases (-B).
  --triggers          Dump triggers for each dumped table.
                      (Defaults to on; use --skip-triggers to disable.)
  --tz-utc            SET TIME_ZONE='+00:00' at top of dump to allow dumping of
                      TIMESTAMP data when a server has data in different time
                      zones or data is being moved between servers with
                      different time zones.
                      (Defaults to on; use --skip-tz-utc to disable.)
  -u, --user=name     User for login if not current user.
  -v, --verbose       Print info about the various stages.
  -V, --version       Output version information and exit.
  -w, --where=name    Dump only selected records. Quotes are mandatory.
  -X, --xml           Dump a database as well formed XML.
  --plugin-dir=name   Directory for client-side plugins.
  --default-auth=name Default authentication client-side plugin to use.
  --enable-cleartext-plugin 
                      Enable/disable the clear text authentication plugin.


Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- ----------------------------------------
all-databases                     FALSE
all-tablespaces                   FALSE
no-tablespaces                    FALSE
add-drop-database                 FALSE
add-drop-table                    TRUE
add-drop-trigger                  FALSE
add-locks                         TRUE
allow-keywords                    FALSE
apply-slave-statements            FALSE
lock-for-backup                   FALSE
bind-address                      (No default value)
character-sets-dir                (No default value)
comments                          TRUE
compatible                        (No default value)
compact                           FALSE
complete-insert                   FALSE
compress                          FALSE
create-options                    TRUE
databases                         FALSE
debug-check                       FALSE
debug-info                        FALSE
default-character-set             utf8
delayed-insert                    FALSE
delete-master-logs                FALSE
disable-keys                      TRUE
dump-slave                        0
events                            FALSE
extended-insert                   TRUE
fields-terminated-by              (No default value)
fields-enclosed-by                (No default value)
fields-optionally-enclosed-by     (No default value)
fields-escaped-by                 (No default value)
flush-logs                        FALSE
flush-privileges                  FALSE
force                             FALSE
hex-blob                          FALSE
host                              (No default value)
include-master-host-port          FALSE
innodb-optimize-keys              FALSE
insert-ignore                     FALSE
ignore-create-error               FALSE
lines-terminated-by               (No default value)
lock-all-tables                   FALSE
lock-tables                       TRUE
log-error                         (No default value)
master-data                       0
max-allowed-packet                25165824
net-buffer-length                 1046528
no-autocommit                     FALSE
no-create-db                      FALSE
no-create-info                    FALSE
no-data                           FALSE
order-by-primary                  FALSE
port                              0
quick                             TRUE
quote-names                       TRUE
replace                           FALSE
routines                          FALSE
set-charset                       TRUE
single-transaction                FALSE
dump-date                         TRUE
socket                            (No default value)
secure-auth                       TRUE
ssl                               FALSE
ssl-ca                            (No default value)
ssl-capath                        (No default value)
ssl-cert                          (No default value)
ssl-cipher                        (No default value)
ssl-key                           (No default value)
ssl-crl                           (No default value)
ssl-crlpath                       (No default value)
ssl-verify-server-cert            FALSE
tab                               (No default value)
triggers                          TRUE
tz-utc                            TRUE
user                              (No default value)
verbose                           FALSE
where                             (No default value)
plugin-dir                        (No default value)
default-auth                      (No default value)
enable-cleartext-plugin           FALSE
[root@bjjxq-b-mysql-10-173 ~]# 












--all-databases  , -A


导出全部数据库。


mysqldump  -uroot -p --all-databases


--all-tablespaces  , -Y


导出全部表空间。


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


--no-tablespaces  , -y


不导出任何表空间信息。


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


--add-drop-database


每个数据库创建之前添加drop数据库语句。


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


--add-drop-table


每个数据表创建之前添加drop数据表语句。(默认为打开状态,使用--skip-add-drop-table取消选项)


mysqldump  -uroot -p --all-databases  (默认添加drop语句)


mysqldump  -uroot -p --all-databases –skip-add-drop-table  (取消drop语句)


--add-locks


在每个表导出之前增加LOCK TABLES并且之后UNLOCK  TABLE。(默认为打开状态,使用--skip-add-locks取消选项)


mysqldump  -uroot -p --all-databases  (默认添加LOCK语句)


mysqldump  -uroot -p --all-databases –skip-add-locks   (取消LOCK语句)


--allow-keywords


允许创建是关键词的列名字。这由表名前缀于每个列名做到。


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


--apply-slave-statements


在'CHANGE MASTER'前添加'STOP SLAVE',并且在导出的最后添加'START SLAVE'。


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


--character-sets-dir


字符集文件的目录


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


--comments


附加注释信息。默认为打开,可以用--skip-comments取消


mysqldump  -uroot -p --all-databases  (默认记录注释)


mysqldump  -uroot -p --all-databases --skip-comments   (取消注释)


--compatible


导出的数据将和其它数据库或旧版本的MySQL 相兼容。值可以为ansi、mysql323、mysql40、postgresql、oracle、mssql、db2、maxdb、no_key_options、no_tables_options、no_field_options等,


要使用几个值,用逗号将它们隔开。它并不保证能完全兼容,而是尽量兼容。


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


--compact


导出更少的输出信息(用于调试)。去掉注释和头尾等结构。可以使用选项:--skip-add-drop-table  --skip-add-locks --skip-comments --skip-disable-keys


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


--complete-insert,  -c


使用完整的insert语句(包含列名称)。这么做能提高插入效率,但是可能会受到max_allowed_packet参数的影响而导致插入失败。


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


--compress, -C


在客户端和服务器之间启用压缩传递所有信息


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


--create-options,  -a


在CREATE TABLE语句中包括所有MySQL特性选项。(默认为打开状态)


mysqldump  -uroot -p --all-databases


--databases,  -B


导出几个数据库。参数后面所有名字参量都被看作数据库名。


mysqldump  -uroot -p --databases test mysql


--debug


输出debug信息,用于调试。默认值为: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


检查内存和打开文件使用说明并退出。


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


--debug-info


输出调试信息并退出


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


--default-character-set


设置默认字符集,默认值为utf8


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


--delayed-insert


采用延时插入方式(INSERT DELAYED)导出数据


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


--delete-master-logs


master备份后删除日志. 这个参数将自动激活--master-data。


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


--disable-keys


对于每个表,用/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;和/*!40000 ALTER TABLE tbl_name ENABLE KEYS */;语句引用INSERT语句。这样可以更快地导入dump出来的文件,因为它是在插入所有行后创建索引的。该选项只适合MyISAM表,默认为打开状态。


mysqldump  -uroot -p --all-databases 


--dump-slave


该选项将导致主的binlog位置和文件名追加到导出数据的文件中。设置为1时,将会以CHANGE MASTER命令输出到数据文件;设置为2时,在命令前增加说明信息。该选项将会打开--lock-all-tables,除非--single-transaction被指定。该选项会自动关闭--lock-tables选项。默认值为0。


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


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


--events, -E


导出事件。


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


--extended-insert,  -e


使用具有多个VALUES列的INSERT语法。这样使导出文件更小,并加速导入时的速度。默认为打开状态,使用--skip-extended-insert取消选项。


mysqldump  -uroot -p --all-databases


mysqldump  -uroot -p --all-databases--skip-extended-insert   (取消选项)


--fields-terminated-by


导出文件中忽略给定字段。与--tab选项一起使用,不能用于--databases和--all-databases选项


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


--fields-enclosed-by


输出文件中的各个字段用给定字符包裹。与--tab选项一起使用,不能用于--databases和--all-databases选项


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


--fields-optionally-enclosed-by


输出文件中的各个字段用给定字符选择性包裹。与--tab选项一起使用,不能用于--databases和--all-databases选项


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


--fields-escaped-by


输出文件中的各个字段忽略给定字符。与--tab选项一起使用,不能用于--databases和--all-databases选项


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


--flush-logs


开始导出之前刷新日志。


请注意:假如一次导出多个数据库(使用选项--databases或者--all-databases),将会逐个数据库刷新日志。除使用--lock-all-tables或者--master-data外。在这种情况下,日志将会被刷新一次,相应的所以表同时被锁定。因此,如果打算同时导出和刷新日志应该使用--lock-all-tables 或者--master-data 和--flush-logs。


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


--flush-privileges


在导出mysql数据库之后,发出一条FLUSH  PRIVILEGES 语句。为了正确恢复,该选项应该用于导出mysql数据库和依赖mysql数据库数据的任何时候。


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


--force


在导出过程中忽略出现的SQL错误。


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


--help


显示帮助信息并退出。


mysqldump  --help


--hex-blob


使用十六进制格式导出二进制字符串字段。如果有二进制数据就必须使用该选项。影响到的字段类型有BINARY、VARBINARY、BLOB。


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


--host, -h


需要导出的主机信息


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


--ignore-table


不导出指定表。指定忽略多个表时,需要重复多次,每次一个表。每个表必须同时指定数据库和表名。例如:--ignore-table=database.table1 --ignore-table=database.table2 ……


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


--include-master-host-port


在--dump-slave产生的'CHANGE  MASTER TO..'语句中增加'MASTER_HOST=<host>,MASTER_PORT=<port>'  


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


--insert-ignore


在插入行时使用INSERT IGNORE语句.


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


--lines-terminated-by


输出文件的每行用给定字符串划分。与--tab选项一起使用,不能用于--databases和--all-databases选项。


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


--lock-all-tables,  -x


提交请求锁定所有数据库中的所有表,以保证数据的一致性。这是一个全局读锁,并且自动关闭--single-transaction 和--lock-tables 选项。


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


--lock-tables,  -l


开始导出前,锁定所有表。用READ  LOCAL锁定表以允许MyISAM表并行插入。对于支持事务的表例如InnoDB和BDB,--single-transaction是一个更好的选择,因为它根本不需要锁定表。


请注意当导出多个数据库时,--lock-tables分别为每个数据库锁定表。因此,该选项不能保证导出文件中的表在数据库之间的逻辑一致性。不同数据库表的导出状态可以完全不同。


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


--log-error


附加警告和错误信息到给定文件


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


--master-data


该选项将binlog的位置和文件名追加到输出文件中。如果为1,将会输出CHANGE MASTER 命令;如果为2,输出的CHANGE  MASTER命令前添加注释信息。该选项将打开--lock-all-tables 选项,除非--single-transaction也被指定(在这种情况下,全局读锁在开始导出时获得很短的时间;其他内容参考下面的--single-transaction选项)。该选项自动关闭--lock-tables选项。


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


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


--max_allowed_packet


服务器发送和接受的最大包长度。


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


--net_buffer_length


TCP/IP和socket连接的缓存大小。


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


--no-autocommit


使用autocommit/commit 语句包裹表。


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


--no-create-db,  -n


只导出数据,而不添加CREATE DATABASE 语句。


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


--no-create-info,  -t


只导出数据,而不添加CREATE TABLE 语句。


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


--no-data, -d


不导出任何数据,只导出数据库表结构。


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


--no-set-names,  -N


等同于--skip-set-charset


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


--opt


等同于--add-drop-table,  --add-locks, --create-options, --quick, --extended-insert, --lock-tables,  --set-charset, --disable-keys 该选项默认开启,  可以用--skip-opt禁用.


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


--order-by-primary


如果存在主键,或者第一个唯一键,对每个表的记录进行排序。在导出MyISAM表到InnoDB表时有效,但会使得导出工作花费很长时间。 


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


--password, -p


连接数据库密码


--pipe(windows系统可用)


使用命名管道连接mysql


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


--port, -P


连接数据库端口号


--protocol


使用的连接协议,包括:tcp, socket, pipe, memory.


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


--quick, -q


不缓冲查询,直接导出到标准输出。默认为打开状态,使用--skip-quick取消该选项。


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


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


--quote-names,-Q


使用(`)引起表和列名。默认为打开状态,使用--skip-quote-names取消该选项。


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


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


--replace


使用REPLACE INTO 取代INSERT INTO.


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


--result-file,  -r


直接输出到指定文件中。该选项应该用在使用回车换行对(\\r\\n)换行的系统上(例如:DOS,Windows)。该选项确保只有一行被使用。


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


--routines, -R


导出存储过程以及自定义函数。


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


--set-charset


添加'SET NAMES  default_character_set'到输出文件。默认为打开状态,使用--skip-set-charset关闭选项。


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


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


--single-transaction


该选项在导出数据之前提交一个BEGIN SQL语句,BEGIN 不会阻塞任何应用程序且能保证导出时数据库的一致性状态。它只适用于多版本存储引擎,仅InnoDB。本选项和--lock-tables 选项是互斥的,因为LOCK  TABLES 会使任何挂起的事务隐含提交。要想导出大表的话,应结合使用--quick 选项。


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


--dump-date


将导出时间添加到输出文件中。默认为打开状态,使用--skip-dump-date关闭选项。


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


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


--skip-opt


禁用–opt选项.


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


--socket,-S


指定连接mysql的socket文件位置,默认路径/tmp/mysql.sock


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


--tab,-T


为每个表在给定路径创建tab分割的文本文件。注意:仅仅用于mysqldump和mysqld服务器运行在相同机器上。


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


--tables


覆盖--databases (-B)参数,指定需要导出的表名。


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


--triggers


导出触发器。该选项默认启用,用--skip-triggers禁用它。


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


--tz-utc


在导出顶部设置时区TIME_ZONE='+00:00' ,以保证在不同时区导出的TIMESTAMP 数据或者数据被移动其他时区时的正确性。


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


--user, -u


指定连接的用户名。


--verbose, --v


输出多种平台信息。


--version, -V


输出mysqldump版本信息并退出


--where, -w


只转储给定的WHERE条件选择的记录。请注意如果条件包含命令解释符专用空格或字符,一定要将条件引用起来。


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


--xml, -X


导出XML格式.


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


--plugin_dir


客户端插件的目录,用于兼容不同的插件版本。


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


--default_auth


客户端插件默认使用权限。


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