文章目录

  • `--opt`
  • `--skip-opt`
  • `--add-drop-table`
  • `--add-locks`
  • `--skip-add-locks`
  • `--allow-keywords`
  • `--all-databases,-A`
  • `--comments`
  • `--skip-comments`
  • `--compact`
  • `--complete-insert,-c`
  • `--compress,-C`
  • `--events,-E`
  • `--compatible`
  • `--skip-disable-keys,-K`
  • `--skip-add-drop-table`
  • `--quick,-q`
  • `--skip-quick`
  • --debug-info
  • `--add-drop-database`
  • `--databases,-B`
  • `--debug`
  • `--default-character-set=charset`
  • `--create-option,-a`
  • `--delayed-insert`
  • `--delete-master-logs`
  • `--disable-keys,-K`
  • `--extended-insert,-e`
  • `--flush-logs,-F`
  • `--flush-privileges`
  • `--force,-f`
  • `--host=host_name,-h host_name`
  • `--hex-blob`
  • `--lock-all-tables,-x`
  • `--lock-tables,-l`
  • `--log-error`
  • `--max_allowed_packet`
  • `--net_buffer_length`
  • `--no-autocommit`
  • `--master-data[=value]`
  • `--dump-slave`
  • `--ignore-table`
  • `--no-create-db,-n`
  • `--no-create-info,-t`
  • `--order-by-primary`
  • `--no-data,-d`
  • `--password[=password],-p[password]`
  • `--port=port_num,-P port_num`
  • `--protocol={TCP | SOCKET | PIPE | MEMORY}`
  • `--dump-date`
  • `--result-file,-r`
  • `--replace`
  • `--quote-names,-Q`
  • `--result-file=file,-r file`
  • `--routines,-R`
  • `--set-charset`
  • `--single-transaction`
  • `--all-tablespaces,-Y`
  • `--no-tablespaces,-y`
  • `--socket=path,-S path`
  • `--tab=path,-T path`
  • `--tables`
  • `--triggers`
  • `--tz-utc`
  • `--user=user_name,-u user_name`
  • `--verbose,-v`
  • `--version,-V`
  • `--where='where-condition',-w 'where-condition'`
  • `--xml,-X`
  • `--help,-?`

--opt

指定选项 --opt 等同于指定
--add-drop-table
--add-locks
--create-options
--disable-keys
--extended-insert
--lock-tables
--quick
--set-charset

如果没有使用 --optmysqldump 就会把整个结果集装载到内存中,然后导出。如果数据非常大就会导致导出失败。

该选项默认开启,但可以用 --skip-opt 禁用。

--skip-opt

--add-drop-table

在每个 CREATE TABLE 语句前添加 DROP TABLE 语句。

--add-locks

在每个表导出之前增加 LOCK TABLES 并且之后 UNLOCK TABLE。也就是会在 INSERT 语句中前后加上 LOCK TABLE 和 UNLOCK TABLE 语句。其作用是防止在这些记录被导入数据库时其他用户(其它线程)对表进行操作。默认开启,可以使用 --skip-add-locks 禁用

--skip-add-locks

取消在每个表导出之前增加 LOCK TABLES,默认存在锁。

--allow-keywords

允许创建关键字列名,在每个列名前面加上表名前缀。

--all-databases,-A

导出全部的数据库

mysqldump -uroot -pqpw123.com --all-databases

--comments

默认值为 1,转储文件中包含额外的信息,例如,服务器版本、主机信息等;设置为 0,则不会包含这些额外的信息。--comments=0 和选项 --skip-comments 等效。

--skip-comments

取消注释信息,默认存在注释信息

参见 --comments 选项的描述。

--compact

产生更紧凑的输出,并会启用以下选项:

--skip-add-drop-table
--no-set-names
--skip-disable-keys
--skip-comments
--skip-add-locks
--skip-set-charset

--complete-insert,-c

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

--compress,-C

压缩在客户端和服务器之间发送的所有信息(如果二者均支持压缩)。

--events,-E

Include Event Scheduler events for the dumped databases in the output. This option requires the EVENT privileges for those databases.

The output generated by using --events contains CREATE EVENT statements to create the events. However, these statements do not include attributes such as the event creation and modification timestamps, so when the events are reloaded, they are created with timestamps equal to the reload time.

If you require events to be created with their original timestamp attributes, do not use --events. Instead, dump and reload the contents of the mysql.event table directly, using a MySQL account that has appropriate privileges for the mysql database.

--compatible

产生与其它数据库系统或旧的 MySQL 服务器更兼容的输出。值可以为 ansi、mysql323、mysql40、postgresql、oracle、mssql、db2、maxdb、no_key_options、no_tables_options、no_field_options。要使用几个值,用逗号将它们隔开。这些值与设置服务器 SQL 模式的相应选项有相同的含义。

它并不保证能完全兼容,而是尽量兼容。它只启用那些目前能够使转储输出更兼容的 SQL 模式值。例如,--compatible=oracle 不映射Oracle 类型或使用 Oracle 注释语法的数据类型。

--skip-disable-keys,-K

--skip-add-drop-table

取消每个数据表创建之前添加 drop 数据表语句。默认每个表之前存在 drop 语句。

--quick,-q

该选项用于转储大的表。这个选项使得 mysqldump 不会先读取全部的内容到内存中再执行输出,它强制 mysqldump 从服务器一次一行地检索表中的行并直接输出,而不是检索所有行并在输出前将它缓存到内存中。

--skip-quick

–debug-info

输出调试信息并退出

--add-drop-database

在每个 CREATE DATABASE 语句前添加 DROP DATABASE 语句,默认不存在。

--databases,-B

转储多个数据库。通常情况,mysqldump 将命令行中的第1个名字参数解析为数据库名,后面的名字解析为表名。使用该选项,它将所有名字参数解析为数据库名。

CREATE DATABASE IF NOT EXISTS db_nameUSE db_name 语句包含在每个新数据库之前的输出中。

--debug

输出 debug 信息,用于调试。默认值为:d:t:o,/tmp/mysqldump.trace

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

--default-character-set=charset

设置默认字符集,如果没有指定,mysqldump 使用 utf8

--create-option,-a

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

特性包括:AUTO_INCREMENT、ENGINE=InnoDB、DEFAULT CHARSET=utf8 等。

--delayed-insert

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

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

--delete-master-logs

备份完成后删除主库上的日志。这个选项会自动打开 --master-data

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

--disable-keys,-K

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

--extended-insert,-e

Write INSERT statements using multiple-row syntax that includes several VALUES lists. This results in a smaller dump file and speeds up inserts when the file is reloaded.

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

--flush-logs,-F

Flush the MySQL server log files before starting the dump. This option requires the RELOAD privilege. If you use this option in combination with the --all-databases option, the logs are flushed for each database dumped. The exception is when using --lock-all-tables, --master-data, or --single-transaction: In this case, the logs are flushed only once,corresponding to the moment that all tables are locked by FLUSH TABLES WITH READ LOCK. If you want your dump and the log flush to happen at exactly the same moment, you should use --flush-logs together with --lock-all-tables, --master-data, or --single-transaction.

在开始导出前刷新服务器的日志文件。我不知道为什么叫“刷新”,我也不知道“刷新”日志文件的意义何在?但是每次刷新操作都会生成一个新的二进制日志文件。而且新的文件内容与旧的文件内容不同。

注意,如果你一次性导出很多数据库(使用 --databases--all-databases 选项),导出每个库时都会触发日志刷新。但是当使用了 --lock-all-tables--master-data 时:日志只会被刷新一次,那个时候所有表都会被锁住。所以如果你希望你的导出和日志刷新发生在同一个确定的时刻,你需要使用 --lock-all-tables 或者 --master-data 配合 --flush-logs

--flush-privileges

在转储mysql数据库后,向转储输出添加一个FLUSH PRIVILEGES语句。每当转储包含mysql数据库和任何其他依赖mysql数据库中的数据进行正确恢复的数据库时,都应使用此选项。

--force,-f

在表转储过程中,即使出现 SQL 错误也继续。在导出过程中忽略出现的SQL错误。

--host=host_name,-h host_name

从给定主机的 MySQL 服务器转储数据。默认主机是 localhost

--hex-blob

使用十六进制格式导出二进制字符串字段(例如,‘abc’ 变为0x616263)。如果有二进制数据就必须使用该选项。影响到的字段类型有BINARY、VARBINARY、BLOB。

--lock-all-tables,-x

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

--lock-tables,-l

开始转储前锁定所有表。用 READ LOCAL 锁定表以允

许并行插入 MyISAM 表。对于事务表例如 InnoDB 和 BDB,--single-transaction 是一个更好的选项,因为它根本不需要锁定表。

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

--log-error

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

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

--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 语句包裹表

--master-data[=value]

–master-data[=value] Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped server. These are the master server coordinates from which the slave should start replicating after you load the dump file into the slave.

If the option value is 2, the CHANGE MASTER TO statement is written as an SQL comment, and thus is informative only; it has no effect when the dump file is reloaded. If the option value is 1, the statement is not written as a comment and takes effect when the dump file is reloaded. If no option value is specified, the default value is 1.

This option requires the RELOAD privilege and the binary log must be enabled.

The --master-data option automatically turns off --lock-tables. It also turns on --lock-all-tables, unless --single-transaction also is specified, in which case, a global read lock is acquired only for a short time at the beginning of the dump (see the description for --single-transaction). In all cases, any action on logs happens at the exact moment of the dump.

It is also possible to set up a slave by dumping an existing slave of the master, using the --dump-slave option, which overrides --master-data and causes it to be ignored if both options are used.

mysqldump 中使用 --master-data=2,会记录 binlog 文件和 position 的信息 。

--dump-slave

该选项将主的binlog位置和文件名追加到导出数据的文件中(show slave status)。设置为1时,将会以CHANGE MASTER命令输出到数据文件;设置为2时,会在change前加上注释。该选项将会打开–lock-all-tables,除非–single-transaction被指定。该选项会自动关闭–lock-tables选项。默认值为0

--ignore-table

不导出指定表。指定忽略多个表时,需要重复多次,每次一个表。每个表必须同时指定数据库和表名。例如:

--ignore-table=database.table1 --ignore-table=database.table2 ……

示例:

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

--no-create-db,-n

取消创建数据库的 SQL 语句,默认存在该 SQL 语句。

该选项禁用 CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name 语句,如果给出 --databases--all-databases 选项,则包含到输出中。

--no-create-info,-t

不要输出创建每个转储表的 CREATE TABLE 语句,这个选项在您只需要数据而不需要DDL(数据库定义语句)时很方便。默认存在。

--order-by-primary

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

--no-data,-d

Do not write any table row information (that is, do not dump table contents). This is useful if you want to dump only the CREATE TABLE statement for the table (for example,to create an empty copy of the table by loading the dump file).

不输出表的任何行信息,即不转储表的内容。这个选项使的 mysqldump 命令不写入 INSERT 语句。如果你只想转储表的结构,即您只需要 DDL 语句时,这个选项很有用。默认导出数据。

--password[=password],-p[password]

连接服务器时使用的密码。如果你使用短选项形式(-p),不能在选项和密码之间有一个空格。如果在命令行中,忽略了 --password-p 选项后面的密码值,将提示你输入一个。

--port=port_num,-P port_num

与一台主机连接时使用的 TCP/IP 端口号。

--protocol={TCP | SOCKET | PIPE | MEMORY}

使用的连接协议。

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

--dump-date

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

--result-file,-r

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

--replace

使用 REPLACE INTO 取代 INSERT INTO

--quote-names,-Q

Quote identifiers (such as database, table, and column names) within ` characters. If the ANSI_QUOTES SQL mode is enabled, identifiers are quoted within " characters.This option is enabled by default. It can be disabled with --skip-quote-names, but this option should be given after any option such as --compatible that may enable --quote-names.

用 (`)字符引用数据库、表和列名。如果 ANSI_QUOTES SQL 模式被激活,则使用(")作为引用符号。默认启用该选项。可以用“–skip-quote-names”禁用,但该选项应跟在其它选项后面才能生效。

--result-file=file,-r file

将输出转向给定的文件。该选项应用在Windows中,因为它禁止将新行‘\n’字符转换为‘\r\n’回车、返回/新行序列。

--routines,-R

Include stored routines (procedures and functions) for the dumped databases in the output. This option requires the SELECT privilege for the mysql.proc table.

注:
1.stored routines 译为存储程序,包括存储过程和函数。
2.该选项在 MySQL 5.1.2 中添加进来。在此之前,存储程序不转储。

--set-charset

Write SET NAMES default_character_set to the output. This option is enabled by default. To suppress the SET NAMES statement, use --skip-set-charset.

将SET NAMES default_character_set加到输出中。该选项默认启用。要想禁用SET NAMES语句,使用–skip-set-charset。

--single-transaction

This option sets the transaction isolation mode to REPEATABLE READ and sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with transactional tables such as InnoDB, because then it dumps the consistent state of the database at the time when START TRANSACTION was issued without blocking any applications.

When using this option, you should keep in mind that only InnoDB tables are dumped in a consistent state. For example, any MyISAM or MEMORY tables dumped while using this option may still change state.

While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates), no other connection should use the following statements:ALTER TABLE, CREATE TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the SELECT that is performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail.

The --single-transaction option and the --lock-tables option are mutually exclusive because LOCK TABLES causes any pending transactions to be committed implicitly.

To dump large tables, combine the --single-transaction option with the --quick option.

该选项在导出数据之前写入一个 START TRANSACTION SQL 语句,它仅对事务表(如 InnoDB)有用,因为它会在启动事务时转储数据库的一致状态,而不会阻塞任何应用程序。本选项和 --lock-tables 选项是互斥的,因为 LOCK TABLES 会使任何挂起的事务隐含提交。要想导出大表的话,应结合使用 --quick 选项。

通过将导出操作封装在一个事务内来使得导出的数据是一个一致性快照。只有当表使用支持 MVCC 的存储引擎(目前只有 InnoDB)时才可以工作;其他引擎不能保证导出是一致的。当导出开启了 --single-transaction 选项时,要确保导出文件有效(正确的表数据和二进制日志位置),就要保证没有其他连接会执行如下语句:ALTER TABLE、DROP TABLE、RENAME TABLE、TRUNCATE TABLE,这会导致一致性快照失效。这个选项开启后会自动关闭 --lock-tables

--single-transaction 会将隔离级别设置成 repeatable-commited

--all-tablespaces,-Y

导出全部表空间。

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

--no-tablespaces,-y

不导出任何表空间信息。

--socket=path,-S path

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

当连接localhost(为默认主机)时使用的套接字文件

--tab=path,-T path

这个选项将会创建两个文件,一个文件包含 DDL 语句或者表创建语句,另一个文件包含数据。DDL 文件被命名为 tbl_name.sql,数据文件被命名为 tbl_name.txt。路径名是存放这两个文件的目录。目录必须已经存在,并且命令的使用者有该目录的相关权限。

注:tbl_name.txt 的内容相当于使用语句 select * from tbl_name into outfile 生成的数据

--tables

覆盖 --database-B 选项。选项后面的所有参数被看作表名。

--triggers

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

--tz-utc

在转储文件中加入 SET TIME_ZONE='+00:00' 以便 TIMESTAMP 列可以在具有不同时区的服务器之间转储和重载。(不使用该选项,TIMESTAMP 列在具有本地时区的源服务器和目的服务器之间转储和重载)。该选项也可以保护由于夏令时带来的更改。该选项默认启用。要想禁用它,使用 --skip-tz-utc。该选项在 MySQL 5.1.2 中加入。

--user=user_name,-u user_name

连接服务器时使用的 MySQL 用户名。

--verbose,-v

Print more information about what the program does.

打印有关程序执行的更多信息。

--version,-V

显示版本信息并退出。

--where='where-condition',-w 'where-condition'

Dump only rows selected by the given WHERE condition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.

只转储给定的WHERE条件选择的记录。如果条件包含空格或特殊的字符(对于命令解释器而言有特殊含义的字符),一定要将条件引用起来。

例如:

--where="user='jimf'"
-w 'userid>100'

--xml,-X

Write dump output as well-formed XML.

以 XML 格式输出

--help,-?

查看使用说明

MySQL命令之mysqldump的选项详解相关推荐

  1. MySQL命令之mysqldump -- 数据库备份程序

    文章目录 命令介绍 常用选项 参考示例 将指定数据表的数据导出为 SQL 脚本文件和文本文件 将指定的多个数据表的数据导出为 SQL 脚本文件和文本文件 将指定数据库导出到脚本文件中 将指定的多个数据 ...

  2. mysql命令导入导出数据库_MYSQL命令行导入导出数据库详解

    Mysql命令行导入数据库: 1,将要导入的.sql文件移至bin文件下,这样的路径比较方便 2,同上面导出的第1步 3,进入MySQL:mysql -u 用户名 -p 如我输入的命令行:mysql ...

  3. mysql完全备份 二进制日志,MySQL二进制日志备份和恢复详解

    原文链接:http://www.showerlee.com/archives/681 ****经实践,该教程ok,特在此分享**** 基本概念 定义: 二进制日志包含了所有更新了数据或者已经潜在更新了 ...

  4. MySQL mysqldump数据导出详解

    MySQL mysqldump数据导出详解 2016-04-07 11:14  pursuer.chen  阅读(357122)  评论(2)  编辑  收藏  举报 介绍 在日常维护工作当中经常会需 ...

  5. php mysql修改命令_PHP编程:mysql alter table命令修改表结构实例详解

    <PHP编程:mysql alter table命令修改表结构实例详解>要点: 本文介绍了PHP编程:mysql alter table命令修改表结构实例详解,希望对您有用.如果有疑问,可 ...

  6. Ffmpeg快速命令使用 Ffmpeg选项详解 Ffmepg格式详解 常见视频文件格式详解

    http://www.ffmpeg.com.cn/index.php/%E9%A6%96%E9%A1%B5 Ffmpeg快速命令使用 From Ffmpeg工程组 Jump to: navigatio ...

  7. MySQLdump之single-transaction详解

    MySQLdump之single-transaction详解 MySQLdump之single-transaction详解 single-transaction 开启general log选项 查看目 ...

  8. mysql启动参数(/etc/my.cnf)详解汇总

    mysql启动参数(/etc/my.cnf)详解汇总 MYSQL–my.cnf配置中文详解 basedir = path 使用给定目录作为根目录(安装目录). character-sets-dir = ...

  9. MySQL的用户密码过期功能详解

    MySQL的用户密码过期功能详解 作者:chszs,未经博主允许不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 先说明两个术语. Payment Ca ...

最新文章

  1. Spring Data(二)查询
  2. 【转贴】pentaho4.5汉化攻略及汉化文件
  3. php 条码打印控件,jQuery插件jquery-barcode实现条码打印的方法
  4. Pandas 读写数据
  5. 配置node.js默认的npm安装目录
  6. 程序设计中的一些感悟
  7. Win10使用tensorflow出现ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败
  8. 台式计算机机箱型号及价格,顶级组装台式电脑配置清单
  9. Ubuntu下键盘测试软件
  10. 5G China unicom AP:B SMS ASCII 转码要求
  11. 微信小游戏保存图片到本地
  12. 期货十三篇 第一篇 警示篇
  13. Java代码实现excel的导入和导出
  14. MSCOMM串口控件在VS2010中的使用
  15. 网络工程师学习笔记——RIP路由汇总实验配置精讲
  16. 耳机插头4根线的含义和技巧
  17. Mac苹果电脑怎样输入表情符号?
  18. android:ellipsize=end在ConstraintLayout中无效的问题
  19. Ubuntu远程桌面修改
  20. vue2-org-tree 树形管理

热门文章

  1. 使用junit进行单元测试_使用JUnit5对DynamoDB应用程序进行单元测试
  2. java私有属性和私有方法_Java 9中什么是私有的?
  3. hystrix应用 博客_用Hystrix保护您的应用程序
  4. JDK 14中的常规,安全和确定性外部内存访问
  5. 如何在不增加人员的情况下自动化API安全程序
  6. 使用Caffeine和Spring Boot的多个缓存配置
  7. Java中的PriorityBlockingQueue
  8. spring boot程序_Spring Boot –现代Java应用程序的基础
  9. github上java项目_GitHub上10,000个最受欢迎的Java项目-以下是他们使用的顶级库
  10. JasperReports:棘手的部分