mysqldump选项:
Format | Description | Introduced |
---|---|---|
--add-drop-database | Add a DROP DATABASE statement before each CREATE DATABASE statement | |
--add-drop-table | Add a DROP TABLE statement before each CREATE TABLE statement | |
--add-drop-trigger | Add a DROP TRIGGER statement before each CREATE TRIGGER statement | |
--add-locks | Surround each table dump with LOCK TABLES and UNLOCK TABLES statements | |
--all-databases | Dump all tables in all databases | |
--allow-keywords | Allow creation of column names that are keywords | |
--apply-slave-statements | Include STOP SLAVE prior to CHANGE MASTER statement and START SLAVE at end of output | |
--bind-address=ip_address | Use specified network interface to connect to MySQL Server | |
--comments | Add comments to the dump file | |
--compact | Produce more compact output | |
--compatible=name[,name,...] | Produce output that is more compatible with other database systems or with older MySQL servers | |
--complete-insert | Use complete INSERT statements that include column names | |
--create-options | Include all MySQL-specific table options in CREATE TABLE statements | |
--databases | Dump several databases | |
--debug[=debug_options] | Write a debugging log | |
--debug-check | Print debugging information when program exits | |
--debug-info | Print debugging information, memory, and CPU statistics when program exits | |
--default-auth=plugin | Authentication plugin to use | |
--default-character-set=charset_name | Specify default character set | |
--defaults-extra-file=file_name | Read option file in addition to usual option files | |
--defaults-file=file_name | Read only named option file | |
--defaults-group-suffix=str | Option group suffix value | |
--delayed-insert | Write INSERT DELAYED statements rather than INSERT statements | |
--delete-master-logs | On a master replication server, delete the binary logs after performing the dump operation | |
--disable-keys | For each table, surround the INSERT statements with statements to disable and enable keys | |
--dump-date | Include dump date as "Dump completed on" comment if --comments is given | |
--dump-slave[=value] | Include CHANGE MASTER statement that lists binary log coordinates of slave's master | |
--events | Dump events from the dumped databases | |
--extended-insert | Use multiple-row INSERT syntax that include several VALUES lists | |
--fields-enclosed-by=string | This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE | |
--fields-escaped-by | This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE | |
--fields-optionally-enclosed-by=string | This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE | |
--fields-terminated-by=string | This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE | |
--flush-logs | Flush the MySQL server log files before starting the dump | |
--flush-privileges | Emit a FLUSH PRIVILEGES statement after dumping the mysql database | |
--help | Display help message and exit | |
--hex-blob | Dump binary columns using hexadecimal notation (for example, 'abc' becomes 0x616263) | |
--host | Host to connect to (IP address or hostname) | |
--ignore-table=db_name.tbl_name | Do not dump the given table | |
--include-master-host-port | Include MASTER_HOST/MASTER_PORT options in CHANGE MASTER statement produced with --dump-slave | |
--insert-ignore | Write INSERT IGNORE statements rather than INSERT statements | |
--lines-terminated-by=string | This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA INFILE | |
--lock-all-tables | Lock all tables across all databases | |
--lock-tables | Lock all tables before dumping them | |
--log-error=file_name | Append warnings and errors to the named file | |
--login-path=name | Read login path options from .mylogin.cnf | 5.6.6 |
--master-data[=value] | Write the binary log file name and position to the output | |
--max_allowed_packet=value | Maximum packet length to send to or receive from server | |
--net_buffer_length=value | Buffer size for TCP/IP and socket communication | |
--no-autocommit | Enclose the INSERT statements for each dumped table within SET autocommit = 0 and COMMIT statements | |
--no-create-db | This option suppresses the CREATE DATABASE statements | |
--no-create-info | Do not write CREATE TABLE statements that re-create each dumped table | |
--no-data | Do not dump table contents | |
--no-defaults | Read no option files | |
--no-set-names | Same as --skip-set-charset | |
--no-tablespaces | Do not write any CREATE LOGFILE GROUP or CREATE TABLESPACE statements in output | |
--opt | Shorthand for --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset. | |
--order-by-primary | Dump each table's rows sorted by its primary key, or by its first unique index | |
--password[=password] | Password to use when connecting to server | |
--pipe | On Windows, connect to server using named pipe | |
--plugin-dir=path | Directory where plugins are installed | |
--port=port_num | TCP/IP port number to use for connection | |
--print-defaults | Print defaults | |
--protocol=type | Connection protocol to use | |
--quick | Retrieve rows for a table from the server a row at a time | |
--quote-names | Quote identifiers within backtick characters | |
--replace | Write REPLACE statements rather than INSERT statements | |
--result-file=file | Direct output to a given file | |
--routines | Dump stored routines (procedures and functions) from the dumped databases | |
--secure-auth | Do not send passwords to the server in old (pre-4.1.1) format | 5.6.17 |
--set-charset | Add SET NAMES default_character_set to output | |
--set-gtid-purged=value | Whether to add SET @@GLOBAL.GTID_PURGED to output | 5.6.9 |
--shared-memory-base-name=name | The name of shared memory to use for shared-memory connections | |
--single-transaction | This option issues a BEGIN SQL statement before dumping data from the server | |
--skip-add-drop-table | Do not add a DROP TABLE statement before each CREATE TABLE statement | |
--skip-add-locks | Do not add locks | |
--skip-comments | Do not add comments to the dump file | |
--skip-compact | Do not produce more compact output | |
--skip-disable-keys | Do not disable keys | |
--skip-extended-insert | Turn off extended-insert | |
--skip-opt | Turn off the options set by --opt | |
--skip-quick | Do not retrieve rows for a table from the server a row at a time | |
--skip-quote-names | Do not quote identifiers | |
--skip-set-charset | Suppress the SET NAMES statement | |
--skip-triggers | Do not dump triggers | |
--skip-tz-utc | Turn off tz-utc | |
--socket=path | For connections to localhost, the Unix socket file to use | |
--ssl | Enable SSL for connection | |
--ssl-ca=file_name | Path of file that contains list of trusted SSL CAs | |
--ssl-capath=dir_name | Path of directory that contains trusted SSL CA certificates in PEM format | |
--ssl-cert=file_name | Path of file that contains X509 certificate in PEM format | |
--ssl-cipher=cipher_list | List of permitted ciphers to use for SSL encryption | |
--ssl-crl=file_name | Path of file that contains certificate revocation lists | 5.6.3 |
--ssl-crlpath=dir_name | Path of directory that contains certificate revocation list files | 5.6.3 |
--ssl-key=file_name | Path of file that contains X509 key in PEM format | |
--ssl-verify-server-cert | Verify server Common Name value in its certificate against host name used when connecting to server | |
--tab=path | Produce tab-separated data files | |
--tables | Override the --databases or -B option | |
--triggers | Dump triggers for each dumped table | |
--tz-utc | Add SET TIME_ZONE='+00:00' to the dump file | |
--user=user_name | MySQL user name to use when connecting to server | |
--verbose | Verbose mode | |
--version | Display version information and exit | |
--where='where_condition' | Dump only rows selected by the given WHERE condition | |
--xml | Produce XML output |
CONNECTION OPTIONS
--bind-address=ip_address
如果一台server上有多个网络接口,用指定的网络接口去连接mysql server,从mysql5.6.1开始支持此选项
--compress, -C
压缩发送在客户端和服务器之间的所有信息
--default-auth=plugin
使用客户端的认证插件
--host=host_name, -h host_name
需要对哪个主机执行mysqldump,默认为localhost
--login-path=name
通过mysql的login_path去登录(通过mysql_config_editor创建)
--password[=password], -p[password]
--host对应的mysql server密码
--pipe, -W
如果通过命名管道去连接,指定命名管道(仅windows平台)
--plugin-dir=path
需要和 --default-auth 选项一起使用,用于提供目录去寻找插件
--port=port_num, -P port_num
--host对应的mysql server端口号
--protocol={TCP|SOCKET|PIPE|MEMORY}
连接时所用的连接协议
附:
--secure-auth
防止老版本的mysql client使用通过旧密码(old_password())加密的密码请求访问。
除此之前,在mysql 5.6.4之前默认值为0,之后改为1。
使用--skip-secure-auth可以跳过此选项。
--socket=path, -S path
指定socket文件。
For connections to localhost, the Unix socket file to
use, or, on Windows, the name of the named pipe to use.
--ssl*
用SSL连接
--user=user_name, -u user_name
--host对应的mysql server的用户名
如果一台server上有多个网络接口,用指定的网络接口去连接mysql server,从mysql5.6.1开始支持此选项
--compress, -C
压缩发送在客户端和服务器之间的所有信息
--default-auth=plugin
使用客户端的认证插件
--host=host_name, -h host_name
需要对哪个主机执行mysqldump,默认为localhost
--login-path=name
通过mysql的login_path去登录(通过mysql_config_editor创建)
--password[=password], -p[password]
--host对应的mysql server密码
--pipe, -W
如果通过命名管道去连接,指定命名管道(仅windows平台)
--plugin-dir=path
需要和 --default-auth 选项一起使用,用于提供目录去寻找插件
--port=port_num, -P port_num
--host对应的mysql server端口号
--protocol={TCP|SOCKET|PIPE|MEMORY}
连接时所用的连接协议
附:
Value | Connection Protocol | Permissible Operating Systems |
---|---|---|
TCP | TCP/IP connection to local or remote server | All |
SOCKET | Unix socket file connection to local server | Unix only |
PIPE | Named-pipe connection to local or remote server | Windows only |
MEMORY | Shared-memory connection to local server | Windows only |
防止老版本的mysql client使用通过旧密码(old_password())加密的密码请求访问。
除此之前,在mysql 5.6.4之前默认值为0,之后改为1。
使用--skip-secure-auth可以跳过此选项。
--socket=path, -S path
指定socket文件。
For connections to localhost, the Unix socket file to
use, or, on Windows, the name of the named pipe to use.
--ssl*
用SSL连接
--user=user_name, -u user_name
--host对应的mysql server的用户名
OPTION-FILE OPTIONS
--defaults-extra-file=file_name
在读取全局选项文件之后,再使用所给定的选项文件,file_name是文件路径,如果该文件不存在或者不可被访问,则会报错。
--defaults-file=file_name
仅使用所给定的选项文件,如果该文件不存在或者不可被访问,则会报错。file_name是文件路径。
--defaults-group-suffix=str
不只读通常的选项组,还读其他的选项组,比如:mysqldump通常读[client]和[mysqldump]选项组,
如果通过对这个选项的指定,mysqldump也会读其他的选项组比如:[client_other]和[mysqldump_other]
--no-defaults
不读任何选项文件,用于避免因为读取了有未知选项的选项文件而导致程序启动失败。
可在读取前生效,除了.mylogin.cnf文件。
--print-defaults
从被提供的选项文件中,输出程序的名字和所有被给予的选项信息。
Print the program name and all options that it gets from option files.
在读取全局选项文件之后,再使用所给定的选项文件,file_name是文件路径,如果该文件不存在或者不可被访问,则会报错。
--defaults-file=file_name
仅使用所给定的选项文件,如果该文件不存在或者不可被访问,则会报错。file_name是文件路径。
--defaults-group-suffix=str
不只读通常的选项组,还读其他的选项组,比如:mysqldump通常读[client]和[mysqldump]选项组,
如果通过对这个选项的指定,mysqldump也会读其他的选项组比如:[client_other]和[mysqldump_other]
--no-defaults
不读任何选项文件,用于避免因为读取了有未知选项的选项文件而导致程序启动失败。
可在读取前生效,除了.mylogin.cnf文件。
--print-defaults
从被提供的选项文件中,输出程序的名字和所有被给予的选项信息。
Print the program name and all options that it gets from option files.
DDL OPTIONS
--add-drop-database
在每一个CREATE DATABASE之前添加DROP DATABASE语句
这个选项通常结合--all-databases和--databases选项使用
--add-drop-table
在每一个CREATE TABLE之前添加DROP TABLE语句
--add-drop-trigger
在每一个CREATE TRIGGER之前添加DROP TRIGGER语句
--all-tablespaces, -Y
导出全部表空间信息
--no-create-db, -n
不会提供CREATE DATABASE语句
--no-create-info, -t
不会提供CREATE TABLE语句
--no-tablespaces, -y
不导出任何表空间信息
--replace
用REPLACE语句(指REPLACE INTO)代替INSERT语句
--comments, -i
在dump文件中输出譬如程序版本,服务器版本,host等信息,该选项默认可用
如果不需要这些信息,用--skip-comments选项
--debug[=debug_options], -# [debug_options]
写debug日志,默认值为d:t:o,默认存放路径为/tmp/mysqldump.trace
--debug-check
当程序运行结束后,打印调试信息
--debug-info
当程序运行结束后,打印调试信息,并且还有内存、CPU用量
--dump-date
默认开启,在程序结束后,将会出现“-- Dump completed on DATE”。
如果需要关闭,则调用--skip-dump-date
--force, -f
当发生SQL error时继续执行(忽略error)
--log-error=file_name
记录警告和错误,通过指定要写入的file_name,默认是不记录
--skip-comments
不删除譬如程序版本,服务器版本,host等信息
--verbose, -v
Verbose mode,输出更多信息
--tab=path, -T path
生成tab分隔符文本格式的文件,
每一个被dump的表,mysqldump会创建以tbl_name.sql文件包含CREATE TABLE语句
同时会创建一个tbl_name.txt的文件来存放数据
此选项不能使用 --all-databases 和 --databases一起使用
而且mysqldump和mysql server需要在同一台机器
比如 mysqldump -u -p database_name --tab=/tmp
--tz-utc
这个选项将设置时区,默认可用,若想置为不可用,则使用--skip-tz-utc
即输出 SET TIME_ZONE='+00:00'
若无这个选项,在数据移动时,将可能不能保证不同时区的TIMESTAMP列的正确性
--xml, -X
以XML格式输出
导出所有数据库中的所有表(包括结构和数据)
--databases, -B
导出所选择的数据库中的所有表(包括结构和数据)
--events, -E
导出event
--ignore-table=db_name.tbl_name
忽略指定的表
--no-data, -d
不导出数据信息,仅导出表结构
--routines, -R
导出ROUTINES(包括存储过程和函数),需要有对mysql.proc表有SELECT权限。
Prior to MySQL 5.6.5, this option had no effect when used together with the --xml option.
(Bug #11760384, Bug #52792)
--tables
覆盖--databases或-B选项,指定要导出的表名。
--triggers
导出Triggers,默认开启,若禁止,则添加--skip-triggers
--where='where_condition', -w 'where_condition'
导出仅仅符合满足where条件的行
比如:
--where="user='jimf'"
-w"userid>1"
-w"userid<1"
对于不支持事务的表,用INSERT DELAYED语句替代INSERT语句
在5.6.6版本,DELAYED插入被弃用,所以这个选项也将在未来的版本中移除。
--disable-keys, -K
对于每张表,为了dump文件更快的导入(INSERT)
在INSERT语句前后加上/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;
和 /*!40000 ALTER TABLE tbl_name ENABLE KEYS */;
这个选项只影响使用MyISAM存储引擎并且没有UNIQUE索引的表。
--extended-insert, -e
在一个INSERT ... VALUES列里写入多行数据,默认为开启,--skip-extended-insert可以禁用。
--insert-ignore
用INSERT IGNORE替代INSERT语句
--opt
默认可用,是--add-drop-table、--add-locks、--create-options、--disable-keys、
--extended-insert、--lock-tables、--quick、--set-charset选项的集合。
这将使dump操作变得更快,同样导入时也将变得更快。--skip-opt可以禁用opt选项。
--quick, -q
这个选项对dump大表非常有用。
强制让mysqldump从服务器查询出来直接输出,而不是将他们放入缓存之后再写入。
添加LOCK TABLES与UNLOCK TABLES语句(默认可用),通过--skip-add-locks禁用该选项
--flush-logs, -F
在开始dump之前刷新mysql server的日志文件
该选项需要有RELOAD权限,如果与--all-databases选项结合使用,日志将会在每个数据库dump前被刷新
如果加了--lock-all-tables、--master-data或者--single-transaction选项时,日志只会被刷新一次
--flush-privileges
在dump mysql数据库之后,发出FLUSH PRIVILEGES语句
--lock-all-tables, -x
锁住所有库的所有表,使用该选项将自动关闭--single-transaction和--lock-tables选项
--lock-tables, -l
在dump之前锁住所有表,通过READ LOCAL允许MyISAM表并行插入INSERT
--single-transaction比--lock-tables更好,因为没有必要锁住所有表
--no-autocommit
禁止自动提交,加入SET autocommit = 0语句,在INSERT执行完成之后执行COMMIT
--order-by-primary
对每个有PRIMARY KEY和UNIQUE约束的表进行排序
在导出MyISAM表到InnoDB表时会有效,但是会大大增加导出时间
--shared-memory-base-name=name
在windows平台上用内存共享方式连接到本地mysql server,默认值是MYSQL,名字区分大小写
--single-transaction
在dump数据前添加START TRANSACTION语句,仅适用于InnoDB表
该选项与--lock-tables不能一起使用,同时在dump很大的表时,该选项要结合--quick一起使用
完整备份一个数据库:
shell> mysqldump db_name > backup-file.sql
装载dump文件到mysql server中:
shell> mysql db_name < backup-file.sql
另一种装载dump文件的方法:
shell> mysql -e "source /path-to-backup/backup-file.sql" db_name
mysqldump同样非常适合于从一个mysql server复制数据到另一个
shell> mysqldump --opt db_name | mysql --host=remote_host -C db_name
可以通过一个mysqldump命令dump几个数据库
shell> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql
dump全部的数据库,可以用--all-databases选项
shell> mysqldump --all-databases > all_databases.sql
对于InnoDB表,mysqldump提供一种在线备份的方式:
shell> mysqldump --all-databases --master-data --single-transaction > all_databases.sql
作者公众号(持续更新)
在每一个CREATE DATABASE之前添加DROP DATABASE语句
这个选项通常结合--all-databases和--databases选项使用
--add-drop-table
在每一个CREATE TABLE之前添加DROP TABLE语句
--add-drop-trigger
在每一个CREATE TRIGGER之前添加DROP TRIGGER语句
--all-tablespaces, -Y
导出全部表空间信息
--no-create-db, -n
不会提供CREATE DATABASE语句
--no-create-info, -t
不会提供CREATE TABLE语句
--no-tablespaces, -y
不导出任何表空间信息
--replace
用REPLACE语句(指REPLACE INTO)代替INSERT语句
DEBUG OPTIONS
--allow-keywords
允许以关键字作为列名创建
--comments, -i
在dump文件中输出譬如程序版本,服务器版本,host等信息,该选项默认可用
如果不需要这些信息,用--skip-comments选项
--debug[=debug_options], -# [debug_options]
写debug日志,默认值为d:t:o,默认存放路径为/tmp/mysqldump.trace
--debug-check
当程序运行结束后,打印调试信息
--debug-info
当程序运行结束后,打印调试信息,并且还有内存、CPU用量
--dump-date
默认开启,在程序结束后,将会出现“-- Dump completed on DATE”。
如果需要关闭,则调用--skip-dump-date
--force, -f
当发生SQL error时继续执行(忽略error)
--log-error=file_name
记录警告和错误,通过指定要写入的file_name,默认是不记录
--skip-comments
不删除譬如程序版本,服务器版本,host等信息
--verbose, -v
Verbose mode,输出更多信息
HELP OPTIONS
--help, -?
展示帮助信息
--version, -V
展示版本信息
展示帮助信息
--version, -V
展示版本信息
INTERNATIONALIZATION OPTIONS
--character-sets-dir=path
指定安装了字符集的路径
--default-character-set=charset_name
默认字符集的设置,如果没有被指定,默认将会使用utf8,更早的版本是latin1
--no-set-names, -N
关闭--set-charset设置
与--skip-set-charset为同义
--set-charset
添加 "SET NAMES default_character_set" 到mysqldump的文件中,默认为可用。
--skip-set-charset可将其设置为不可用
在"CHANGE MASTER TO"前添加"STOP SLAVE"语句,并且在最后添加"START SLAVE"
--delete-master-logs
在主复制结构服务器dump操作结束后,通过PURGE BINARY LOGS来删除二进制日志,这个选项将同时使--master-data选项打开
--dump-slave[=value]
参考--master-data用法。
默认值为1,输出"CHANGE MASTER TO"语句,若为2,则作为注释。
--include-master-host-port
添加master server的host和master server port
比如 MASTER_HOST=[host],MASTER_PORT=[port]
--master-data[=value]
默认值为1,dump文件会额外输出譬如“CHANGE MASTER TO MASTER_LOG_FILE='bin-log.000001', MASTER_LOG_POS=xxxx;”的语句,
便于设置从何处读取主server的二进制日志。
如果将值设置为2,“CHANGE MASTER TO”语句将成为SQL注释,仅仅作为告知信息。
该选项需要RELOAD权限并且二进制日志可用。
如果用了--dump-slave选项,将会覆盖--master-data选项。
该选项常用于dump master的数据,并建立slave时所用。
--set-gtid-purged=value
这个选项可以将GTID信息写入dump文件,形如SET @@global.gtid_purged语句。
默认的值为AUTO。该选项在5.6.9以上可用。
生成更少的输出信息,是--skip-add-drop-table、--skip-add-locks、
--skip-comments、--skip-disable-keys、--skip-set-charset的集合。
--compatible=name
生成可以兼容其他数据库系统或者老版本mysql server的dump文件
其值可以为 ansi mysql323 mysql40 postgresql oracle mssql db2 maxdb
no_key_options no_table_options no_field_options
如果同时用多个值,则通过逗号来分割他们,这些值同sql mode的值
这个选项不保证可以完全兼容其他数据库系统,仅仅是使那些使用了对应值的sql mode可以dump出更多兼容性的语句。
比如--compatible=oracle并不是将数据类型映射成oracle的数据类型或者说用oracle的SQL语法。
--complete-insert, -c
用完整的INSERT语句(包含列的名字)
--create-options
在CREATE TABLE语句中添加包含所有具有mysql特性的选项
--fields-terminated-by=..., --fields-enclosed-by=..., --fields-optionally-enclosed-by=..., --fields-escaped-by=...
这些选项需和--tab选项配合使用,用法与SELECT ... INTO OUTFILE类似,用于LOAD DATA INFILE
--hex-blob
将数据类型为BINARY VARBINARY BLOB BIT的列输出成十六进制的格式
比如'abc'输出为0x616263
--lines-terminated-by=...
该选项需要配合--tab选项使用,用于指定每行的分隔符,用于LOAD DATA INFILE
--quote-names, -Q
指定包裹标识符为'`',比如针对database,table,column名字的包裹符(如`test`)
默认该选项是可用的,如果要置为不可用,则指定--skip-quote-names
--result-file=file_name, -r file_name
直接输出到被提供的文件,这个选项保证在windows中,换行符能够被正确使用(将"\n"转换成"\r\n")
指定安装了字符集的路径
--default-character-set=charset_name
默认字符集的设置,如果没有被指定,默认将会使用utf8,更早的版本是latin1
--no-set-names, -N
关闭--set-charset设置
与--skip-set-charset为同义
--set-charset
添加 "SET NAMES default_character_set" 到mysqldump的文件中,默认为可用。
--skip-set-charset可将其设置为不可用
REPLICATION OPTIONS
--apply-slave-statements在"CHANGE MASTER TO"前添加"STOP SLAVE"语句,并且在最后添加"START SLAVE"
--delete-master-logs
在主复制结构服务器dump操作结束后,通过PURGE BINARY LOGS来删除二进制日志,这个选项将同时使--master-data选项打开
--dump-slave[=value]
参考--master-data用法。
默认值为1,输出"CHANGE MASTER TO"语句,若为2,则作为注释。
--include-master-host-port
添加master server的host和master server port
比如 MASTER_HOST=[host],MASTER_PORT=[port]
--master-data[=value]
默认值为1,dump文件会额外输出譬如“CHANGE MASTER TO MASTER_LOG_FILE='bin-log.000001', MASTER_LOG_POS=xxxx;”的语句,
便于设置从何处读取主server的二进制日志。
如果将值设置为2,“CHANGE MASTER TO”语句将成为SQL注释,仅仅作为告知信息。
该选项需要RELOAD权限并且二进制日志可用。
如果用了--dump-slave选项,将会覆盖--master-data选项。
该选项常用于dump master的数据,并建立slave时所用。
--set-gtid-purged=value
这个选项可以将GTID信息写入dump文件,形如SET @@global.gtid_purged语句。
默认的值为AUTO。该选项在5.6.9以上可用。
-
Value Meaning OFF Add no SET statement to the output. ON Add a SET statement to the output. An error occurs if GTIDs are not enabled on the server. AUTO Add a SET statement to the output if GTIDs are enabled on the server.
FORMAT OPTIONS
--compact生成更少的输出信息,是--skip-add-drop-table、--skip-add-locks、
--skip-comments、--skip-disable-keys、--skip-set-charset的集合。
--compatible=name
生成可以兼容其他数据库系统或者老版本mysql server的dump文件
其值可以为 ansi mysql323 mysql40 postgresql oracle mssql db2 maxdb
no_key_options no_table_options no_field_options
如果同时用多个值,则通过逗号来分割他们,这些值同sql mode的值
这个选项不保证可以完全兼容其他数据库系统,仅仅是使那些使用了对应值的sql mode可以dump出更多兼容性的语句。
比如--compatible=oracle并不是将数据类型映射成oracle的数据类型或者说用oracle的SQL语法。
--complete-insert, -c
用完整的INSERT语句(包含列的名字)
--create-options
在CREATE TABLE语句中添加包含所有具有mysql特性的选项
--fields-terminated-by=..., --fields-enclosed-by=..., --fields-optionally-enclosed-by=..., --fields-escaped-by=...
这些选项需和--tab选项配合使用,用法与SELECT ... INTO OUTFILE类似,用于LOAD DATA INFILE
--hex-blob
将数据类型为BINARY VARBINARY BLOB BIT的列输出成十六进制的格式
比如'abc'输出为0x616263
--lines-terminated-by=...
该选项需要配合--tab选项使用,用于指定每行的分隔符,用于LOAD DATA INFILE
--quote-names, -Q
指定包裹标识符为'`',比如针对database,table,column名字的包裹符(如`test`)
默认该选项是可用的,如果要置为不可用,则指定--skip-quote-names
--result-file=file_name, -r file_name
直接输出到被提供的文件,这个选项保证在windows中,换行符能够被正确使用(将"\n"转换成"\r\n")
--tab=path, -T path
生成tab分隔符文本格式的文件,
每一个被dump的表,mysqldump会创建以tbl_name.sql文件包含CREATE TABLE语句
同时会创建一个tbl_name.txt的文件来存放数据
此选项不能使用 --all-databases 和 --databases一起使用
而且mysqldump和mysql server需要在同一台机器
比如 mysqldump -u -p database_name --tab=/tmp
--tz-utc
这个选项将设置时区,默认可用,若想置为不可用,则使用--skip-tz-utc
即输出 SET TIME_ZONE='+00:00'
若无这个选项,在数据移动时,将可能不能保证不同时区的TIMESTAMP列的正确性
--xml, -X
以XML格式输出
Value: | XML Representation: |
---|---|
NULL (unknown value) | <field name="column_name" xsi:nil="true" /> |
'' (empty string) | <field name="column_name"> |
'NULL' (string value) | <field name="column_name">NULL |
FILTERING OPTIONS
--all-databases, -A导出所有数据库中的所有表(包括结构和数据)
--databases, -B
导出所选择的数据库中的所有表(包括结构和数据)
--events, -E
导出event
--ignore-table=db_name.tbl_name
忽略指定的表
--no-data, -d
不导出数据信息,仅导出表结构
--routines, -R
导出ROUTINES(包括存储过程和函数),需要有对mysql.proc表有SELECT权限。
Prior to MySQL 5.6.5, this option had no effect when used together with the --xml option.
(Bug #11760384, Bug #52792)
--tables
覆盖--databases或-B选项,指定要导出的表名。
--triggers
导出Triggers,默认开启,若禁止,则添加--skip-triggers
--where='where_condition', -w 'where_condition'
导出仅仅符合满足where条件的行
比如:
--where="user='jimf'"
-w"userid>1"
-w"userid<1"
PERFORMANCE OPTIONS
--delayed-insert对于不支持事务的表,用INSERT DELAYED语句替代INSERT语句
在5.6.6版本,DELAYED插入被弃用,所以这个选项也将在未来的版本中移除。
--disable-keys, -K
对于每张表,为了dump文件更快的导入(INSERT)
在INSERT语句前后加上/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;
和 /*!40000 ALTER TABLE tbl_name ENABLE KEYS */;
这个选项只影响使用MyISAM存储引擎并且没有UNIQUE索引的表。
--extended-insert, -e
在一个INSERT ... VALUES列里写入多行数据,默认为开启,--skip-extended-insert可以禁用。
--insert-ignore
用INSERT IGNORE替代INSERT语句
--opt
默认可用,是--add-drop-table、--add-locks、--create-options、--disable-keys、
--extended-insert、--lock-tables、--quick、--set-charset选项的集合。
这将使dump操作变得更快,同样导入时也将变得更快。--skip-opt可以禁用opt选项。
--quick, -q
这个选项对dump大表非常有用。
强制让mysqldump从服务器查询出来直接输出,而不是将他们放入缓存之后再写入。
TRANSACTIONAL OPTIONS
--add-locks添加LOCK TABLES与UNLOCK TABLES语句(默认可用),通过--skip-add-locks禁用该选项
--flush-logs, -F
在开始dump之前刷新mysql server的日志文件
该选项需要有RELOAD权限,如果与--all-databases选项结合使用,日志将会在每个数据库dump前被刷新
如果加了--lock-all-tables、--master-data或者--single-transaction选项时,日志只会被刷新一次
--flush-privileges
在dump mysql数据库之后,发出FLUSH PRIVILEGES语句
--lock-all-tables, -x
锁住所有库的所有表,使用该选项将自动关闭--single-transaction和--lock-tables选项
--lock-tables, -l
在dump之前锁住所有表,通过READ LOCAL允许MyISAM表并行插入INSERT
--single-transaction比--lock-tables更好,因为没有必要锁住所有表
--no-autocommit
禁止自动提交,加入SET autocommit = 0语句,在INSERT执行完成之后执行COMMIT
--order-by-primary
对每个有PRIMARY KEY和UNIQUE约束的表进行排序
在导出MyISAM表到InnoDB表时会有效,但是会大大增加导出时间
--shared-memory-base-name=name
在windows平台上用内存共享方式连接到本地mysql server,默认值是MYSQL,名字区分大小写
--single-transaction
在dump数据前添加START TRANSACTION语句,仅适用于InnoDB表
该选项与--lock-tables不能一起使用,同时在dump很大的表时,该选项要结合--quick一起使用
用法简单介绍:
完整备份一个数据库:
shell> mysqldump db_name > backup-file.sql
装载dump文件到mysql server中:
shell> mysql db_name < backup-file.sql
另一种装载dump文件的方法:
shell> mysql -e "source /path-to-backup/backup-file.sql" db_name
mysqldump同样非常适合于从一个mysql server复制数据到另一个
shell> mysqldump --opt db_name | mysql --host=remote_host -C db_name
可以通过一个mysqldump命令dump几个数据库
shell> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql
dump全部的数据库,可以用--all-databases选项
shell> mysqldump --all-databases > all_databases.sql
对于InnoDB表,mysqldump提供一种在线备份的方式:
shell> mysqldump --all-databases --master-data --single-transaction > all_databases.sql
作者公众号(持续更新)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29773961/viewspace-1871861/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29773961/viewspace-1871861/