mysqldump 客户端实用程序执行逻辑备份,生成一组 SQL 语句,执行这些语句可以重现原始数据库对象定义和表数据。它转储一个或多个 MySQL 数据库以进行备份或传输到另一台 SQL 服务器。 mysqldump 命令还可以生成 CSV、其他分隔文本或 XML 格式的输出。The mysqldump client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data. It dumps one or more MySQL databases for backup or transfer to another SQL server. The mysqldump command can also generate output in CSV, other delimited text, or XML format.
考虑使用 MySQL Shell 转储实用程序,它提供多线程并行转储、文件压缩和进度信息显示,以及 Oracle 云基础设施对象存储流和 MySQL HeatWave 兼容性检查和修改等云功能。使用 MySQL Shell 负载转储实用程序可以轻松地将转储导入到 MySQL 服务器实例或 MySQL HeatWave 数据库系统中。 MySQL Shell 的安装说明可以在此处找到。Consider using the MySQL Shell dump utilities, which provide parallel dumping with multiple threads, file compression, and progress information display, as well as cloud features such as Oracle Cloud Infrastructure Object Storage streaming, and MySQL HeatWave compatibility checks and modifications. Dumps can be easily imported into a MySQL Server instance or a MySQL HeatWave DB System using the MySQL Shell load dump utilities. Installation instructions for MySQL Shell can be found here.
mysqldump 至少需要转储表的 SELECT 权限,SHOW VIEW 用于转储视图,TRIGGER 用于转储触发器,LOCK TABLES如果--single-transaction选项未使用,PROCESS如果--no-tablespaces 选项未使用,并且 RELOAD 或 FLUSH_TABLES 权限,具有--single-transaction,如果gtid_mode=ON和gtid_purged=ON|AUTO。某些选项可能需要其他权限,如选项说明中所述。mysqldump requires at least the
SELECT privilege for dumped
tables, SHOW VIEW for dumped
views, TRIGGER for dumped
triggers, LOCK TABLES if the
--single-transaction option is
not used, PROCESS if the
--no-tablespaces
option is not used, and the
RELOAD or
FLUSH_TABLES privilege with
--single-transaction
if both gtid_mode=ON
and gtid_purged=ON|AUTO.
Certain options might require other privileges as noted in the
option descriptions.
要重新加载转储文件,您必须拥有执行其中包含的语句所需的权限,例如对这些语句创建的对象的适当的 CREATE 权限。To reload a dump file, you must have the privileges required to
execute the statements that it contains, such as the appropriate
CREATE privileges for objects created by
those statements.
mysqldump 输出可以包括 ALTER DATABASE 更改数据库排序规则的语句。在转储存储程序以保留其字符编码时可以使用这些。要重新加载包含此类语句的转储文件,需要受影响数据库的 ALTER 权限。mysqldump output can include
ALTER DATABASE statements that
change the database collation. These may be used when dumping
stored programs to preserve their character encodings. To reload
a dump file containing such statements, the
ALTER privilege for the affected database is
required.
在 Windows 上使用 PowerShell 并通过输出重定向创建的转储会生成一个具有 UTF-16 编码的文件:A dump made using PowerShell on Windows with output redirection creates a file that has UTF-16 encoding:
mysqldump [options] > dump.sql
但是,不允许使用 UTF-16 作为连接字符集(请参阅不允许的客户端字符集),因此无法正确加载转储文件。要解决此问题,请使用 --result-file 选项,该选项以 ASCII 格式创建输出:However, UTF-16 is not permitted as a connection character set
(see
Impermissible Client Character Sets),
so the dump file cannot be loaded correctly. To work around
this issue, use the --result-file option,
which creates the output in ASCII format:
mysqldump [options] --result-file=dump.sql
如果转储文件包含系统表,则不建议在服务器上启用 GTID 时加载转储文件 (gtid_mode=ON)。 mysqldump 向使用非事务性 MyISAM 存储引擎的系统表发出 DML 指令,并且在启用 GTID 时不允许这种组合。It is not recommended to load a dump file when GTIDs are enabled
on the server (gtid_mode=ON),
if your dump file includes system tables.
mysqldump issues DML instructions for the
system tables which use the non-transactional MyISAM storage
engine, and this combination is not permitted when GTIDs are
enabled.
性能和可扩展性注意事项Performance and Scalability Considerations
mysqldump 优点包括在恢复之前查看甚至编辑输出的方便性和灵活性。您可以克隆数据库以进行开发和 DBA 工作,或者对现有数据库进行细微的修改以进行测试。它并不是用于备份大量数据的快速或可扩展的解决方案。对于大数据量,即使备份步骤需要合理的时间,恢复数据也可能非常慢,因为重放 SQL 语句涉及插入、创建索引等磁盘 I/O。mysqldump advantages include the convenience
and flexibility of viewing or even editing the output before
restoring. You can clone databases for development and DBA work,
or produce slight variations of an existing database for
testing. It is not intended as a fast or scalable solution for
backing up substantial amounts of data. With large data sizes,
even if the backup step takes a reasonable time, restoring the
data can be very slow because replaying the SQL statements
involves disk I/O for insertion, index creation, and so on.
对于大规模备份和恢复,物理备份更合适,以原始格式复制数据文件,以便快速恢复。For large-scale backup and restore, a physical backup is more appropriate, to copy the data files in their original format so that they can be restored quickly.
如果您的表主要是 InnoDB 表,或者您混合使用 InnoDB 和 MyISAM 表,请考虑使用 mysqlbackup,它作为 MySQL Enterprise 的一部分提供。该工具以最小的中断为 InnoDB 备份提供高性能;它还可以备份来自MyISAM和其他存储引擎的表;它还提供了许多方便的选项来适应不同的备份场景。请参阅第 32.1 节“MySQL Enterprise 备份概述”。If your tables are primarily InnoDB
tables, or if you have a mix of InnoDB and
MyISAM tables, consider using
mysqlbackup, which is available as part of
MySQL Enterprise. This tool provides high performance for
InnoDB backups with minimal disruption; it
can also back up tables from MyISAM and other
storage engines; it also provides a number of convenient options
to accommodate different backup scenarios. See
Section 32.1, “MySQL Enterprise Backup Overview”.
mysqldump可以逐行检索并导出表内容,或者可以从表中检索整个内容并先在内存中缓冲,然后再导出。如果导出大表,内存缓冲可能会成为问题。要逐行导出表,请使用--quick选项(或--opt,它启用--quick). The
--opt选项(因此--quick)默认启用,因此要启用内存缓冲,请使用--skip-quick.mysqldump can retrieve and dump table
contents row by row, or it can retrieve the entire content from
a table and buffer it in memory before dumping it. Buffering in
memory can be a problem if you are dumping large tables. To dump
tables row by row, use the
--quick option (or
--opt, which enables
--quick). The
--opt option (and hence
--quick) is enabled by
default, so to enable memory buffering, use
--skip-quick.
如果您使用最新版本的 mysqldump 生成要重新加载到非常旧的 MySQL 服务器中的转储,请使用 --skip-opt 选项,而不是 --opt 或 --extended-insert 选项。If you are using a recent version of
mysqldump to generate a dump to be reloaded
into a very old MySQL server, use the
--skip-opt option instead of
the --opt or
--extended-insert option.
有关 mysqldump,请参阅第 9.4 节“使用 mysqldump 进行备份”。For additional information about mysqldump, see Section 9.4, “Using mysqldump for Backups”.
调用语法Invocation Syntax
一般有三种方法使用mysqldump — 转储一组一个或多个表、一组一个或多个完整数据库或整个 MySQL 服务器 - 如下所示:There are in general three ways to use mysqldump—in order to dump a set of one or more tables, a set of one or more complete databases, or an entire MySQL server—as shown here:
mysqldump [options]db_name[tbl_name...] mysqldump [options] --databasesdb_name... mysqldump [options] --all-databases
要转储整个数据库,请勿在 db_name 后命名任何表,或使用 --databases 或 --all-databases 选项。To dump entire databases, do not name any tables following
db_name, or use the
--databases or
--all-databases option.
要查看您的 mysqldump 版本支持的选项列表,请发出命令 mysqldump --help。To see a list of the options your version of
mysqldump supports, issue the command
mysqldump
--help.
选项语法 - 按字母顺序排列的摘要Option Syntax - Alphabetical Summary
mysqldump 支持以下选项,可以在命令行或选项文件的 [mysqldump] 和 [client] 组中指定。有关 MySQL 程序使用的选项文件的信息,请参阅第 6.2.2.2 节“使用选项文件”。mysqldump supports the following options,
which can be specified on the command line or in the
[mysqldump] and [client]
groups of an option file. For information about option files
used by MySQL programs, see Section 6.2.2.2, “Using Option Files”.
表 6.13 mysqldump 选项Table 6.13 mysqldump Options
| 选项名称Option Name | 说明Description |
|---|---|
| --添加删除数据库--add-drop-database | 在每个 CREATE DATABASE 语句之前添加 DROP DATABASE 语句Add DROP DATABASE statement before each CREATE DATABASE statement |
| --添加删除表--add-drop-table | 在每个 CREATE TABLE 语句之前添加 DROP TABLE 语句Add DROP TABLE statement before each CREATE TABLE statement |
| --添加删除触发器--add-drop-trigger | 在每个 CREATE TRIGGER 语句之前添加 DROP TRIGGER 语句Add DROP TRIGGER statement before each CREATE TRIGGER statement |
| --添加锁定--add-locks | 使用 LOCK TABLES 和 UNLOCK TABLES 语句包围每个表转储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-replica-statements | 在 CHANGE REPLICATION SOURCE TO 语句之前包含 STOP REPLICA,并在输出结束时包含 START REPLICAInclude STOP REPLICA prior to CHANGE REPLICATION SOURCE TO statement and START REPLICA at end of output |
| --应用从属语句--apply-slave-statements | 在 CHANGE MASTER 语句之前包含 STOP SLAVE,并在输出结束时包含 START SLAVEInclude STOP SLAVE prior to CHANGE MASTER statement and START SLAVE at end of output |
| --绑定地址--bind-address | 使用指定的网络接口连接到 MySQL 服务器Use specified network interface to connect to MySQL Server |
| --字符集目录--character-sets-dir | 安装字符集的目录Directory where character sets are installed |
| --列统计--column-statistics | 编写 ANALYZE TABLE 语句以生成统计直方图Write ANALYZE TABLE statements to generate statistics histograms |
| --评论--comments | 向转储文件添加注释Add comments to dump file |
| --精简--compact | 产生更紧凑的输出Produce more compact output |
| --兼容--compatible | 生成与其他数据库系统或旧版 MySQL 服务器更兼容的输出Produce output that is more compatible with other database systems or with older MySQL servers |
| --完整插入--complete-insert | 使用包含列名的完整 INSERT 语句Use complete INSERT statements that include column names |
| --压缩--compress | 压缩客户端和服务器之间发送的所有信息Compress all information sent between client and server |
| --压缩算法--compression-algorithms | 允许用于连接服务器的压缩算法Permitted compression algorithms for connections to server |
| --创建选项--create-options | 在 CREATE TABLE 语句中包含所有特定于 MySQL 的表选项Include all MySQL-specific table options in CREATE TABLE statements |
| --数据库--databases | 将所有名称参数解释为数据库名称Interpret all name arguments as database names |
| --调试--debug | 写调试日志Write debugging log |
| --调试检查--debug-check | 程序退出时打印调试信息Print debugging information when program exits |
| --调试信息--debug-info | 在程序退出时打印调试信息、内存和 CPU 统计信息Print debugging information, memory, and CPU statistics when program exits |
| --默认认证--default-auth | 要使用的身份验证插件Authentication plugin to use |
| --默认字符集--default-character-set | 指定默认字符集Specify default character set |
| --附加默认文件--defaults-extra-file | 除了常规选项文件外,读取指定名称的选项文件Read named option file in addition to usual option files |
| --默认文件--defaults-file | 仅读取指定的选项文件Read only named option file |
| --默认组后缀--defaults-group-suffix | 选项组后缀值Option group suffix value |
| --删除主日志--delete-master-logs | 在复制源服务器上,执行转储操作后删除二进制日志On a replication source server, delete the binary logs after performing the dump operation |
| --删除源日志--delete-source-logs | 在复制源服务器上,执行转储操作后删除二进制日志On a replication source server, delete the binary logs after performing the dump operation |
| --禁用键--disable-keys | 对于每个表,用禁用和启用键的语句包围 INSERT 语句For each table, surround INSERT statements with statements to disable and enable keys |
| --导出日期--dump-date | 如果给出 --comments,则将转储日期包含为“转储完成日期”注释Include dump date as "Dump completed on" comment if --comments is given |
| --转储副本--dump-replica | 包含 CHANGE REPLICATION SOURCE TO 语句,列出副本源的二进制日志坐标Include CHANGE REPLICATION SOURCE TO statement that lists binary log coordinates of replica's source |
| --转储从库--dump-slave | 包含列出副本源的二进制日志坐标的 CHANGE MASTER 语句Include CHANGE MASTER statement that lists binary log coordinates of replica's source |
| --启用明文插件--enable-cleartext-plugin | 启用明文身份验证插件Enable cleartext authentication plugin |
| --事件--events | 从转储数据库中转储事件Dump events from dumped databases |
| --扩展插入--extended-insert | 使用多行 INSERT 语法Use multiple-row INSERT syntax |
| --字段用引号括起--fields-enclosed-by | 该选项与 --tab 选项一起使用,与 LOAD DATA 的相应子句含义相同This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA |
| --字段使用转义符--fields-escaped-by | 该选项与 --tab 选项一起使用,与 LOAD DATA 的相应子句含义相同This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA |
| --fields-选择性封闭-by--fields-optionally-enclosed-by | 该选项与 --tab 选项一起使用,与 LOAD DATA 的相应子句含义相同This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA |
| --字段分隔符--fields-terminated-by | 该选项与 --tab 选项一起使用,与 LOAD DATA 的相应子句含义相同This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA |
| --刷新日志--flush-logs | 开始转储之前刷新 MySQL 服务器日志文件Flush MySQL server log files before starting dump |
| --刷新权限--flush-privileges | 转储 mysql 数据库后发出 FLUSH PRIVILEGES 语句Emit a FLUSH PRIVILEGES statement after dumping mysql database |
| --强制执行--force | 即使在表转储期间发生 SQL 错误也继续Continue even if an SQL error occurs during a table dump |
| --获取服务器公钥--get-server-public-key | 从服务器请求 RSA 公钥Request RSA public key from server |
| --帮助--help | 显示帮助信息并退出Display help message and exit |
| --十六进制二进制大对象--hex-blob | 使用十六进制表示法转储二进制列Dump binary columns using hexadecimal notation |
| --主机--host | MySQL 服务器所在的主机Host on which MySQL server is located |
| --忽略错误--ignore-error | 忽略指定的错误Ignore specified errors |
| --忽略表--ignore-table | 不要转储给定的表Do not dump given table |
| --忽略视图--ignore-views | 跳过转储表视图Skip dumping table views |
| --包含主机端口--include-master-host-port | 在使用 --dump-slave 生成的 CHANGE MASTER 语句中包含 MASTER_HOST/MASTER_PORT 选项Include MASTER_HOST/MASTER_PORT options in CHANGE MASTER statement produced with --dump-slave |
| --包含源主机端口--include-source-host-port | 在使用 --dump-replica 生成的 CHANGE REPLICATION SOURCE TO 语句中包含 SOURCE_HOST 和 SOURCE_PORT 选项Include SOURCE_HOST and SOURCE_PORT options in CHANGE REPLICATION SOURCE TO statement produced with --dump-replica |
| --初始化命令--init-command | 连接或重新连接 MySQL 服务器后执行的单个 SQL 语句;重置现有定义的命令Single SQL statement to execute after connecting or re-connecting to MySQL server; resets existing defined commands |
| --初始化命令添加--init-command-add | 添加一条额外的 SQL 语句,在连接或重新连接 MySQL 服务器后执行Add an additional SQL statement to execute after connecting or re-connecting to MySQL server |
| --插入忽略--insert-ignore | 编写 INSERT IGNORE 而不是 INSERT 语句Write INSERT IGNORE rather than INSERT statements |
| --行终止符--lines-terminated-by | 该选项与 --tab 选项一起使用,与 LOAD DATA 的相应子句含义相同This option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA |
| --锁定所有表--lock-all-tables | 锁定所有数据库中的所有表Lock all tables across all databases |
| --锁定表--lock-tables | 在转储之前锁定所有表Lock all tables before dumping them |
| --记录错误--log-error | 将警告和错误附加到指定文件Append warnings and errors to named file |
| --登录路径--login-path | 从 .mylogin.cnf 读取登录路径选项Read login path options from .mylogin.cnf |
| --主数据--master-data | 将二进制日志文件名和位置写入输出Write the binary log file name and position to the output |
| --最大允许数据包--max-allowed-packet | 发送到服务器或从服务器接收的最大数据包长度Maximum packet length to send to or receive from server |
| --mysqld-长查询时间--mysqld-long-query-time | 慢速查询阈值的会话值Session value for slow query threshold |
| --网络缓冲长度--net-buffer-length | TCP/IP 和套接字通信的缓冲区大小Buffer size for TCP/IP and socket communication |
| --网络超时--network-timeout | 增加网络超时以允许更大的表转储Increase network timeouts to permit larger table dumps |
| --无自动提交--no-autocommit | 将每个转储表的 INSERT 语句包含在 SET autocommit = 0 和 COMMIT 语句中Enclose the INSERT statements for each dumped table within SET autocommit = 0 and COMMIT statements |
| --不创建数据库--no-create-db | 不要编写 CREATE DATABASE 语句Do not write CREATE DATABASE statements |
| --不创建表信息--no-create-info | 不要编写重新创建每个转储表的 CREATE TABLE 语句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-login-paths | 不要从登录路径文件中读取登录路径Do not read login paths from the login path file |
| --不设置字符集--no-set-names | 与--skip-set-charset 相同Same as --skip-set-charset |
| --无表空间--no-tablespaces | 不要在输出中写入任何 CREATE LOGFILE GROUP 或 CREATE TABLESPACE 语句Do not write any CREATE LOGFILE GROUP or CREATE TABLESPACE statements in output |
| --优化--opt | 简写 --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charsetShorthand 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 |
| --输出为版本--output-as-version | 确定转储中使用的副本和事件术语;为了与旧版本兼容Determines replica and event terminology used in dumps; for compatibility with older versions |
| --密码--password | 连接服务器时使用的密码Password to use when connecting to server |
| --密码 1--password1 | 首次多因素身份验证密码,用于连接服务器First multifactor authentication password to use when connecting to server |
| --密码 2--password2 | 连接服务器时使用的第二个多因素认证密码Second multifactor authentication password to use when connecting to server |
| --密码 3--password3 | 连接服务器时使用的第三个多因素认证密码Third multifactor authentication password to use when connecting to server |
| --管道--pipe | 使用命名管道连接到服务器(仅限 Windows)Connect to server using named pipe (Windows only) |
| --插件认证 Kerberos 客户端模式--plugin-authentication-kerberos-client-mode | 允许在 Windows 上通过 MIT Kerberos 库进行 GSSAPI 可插入身份验证Permit GSSAPI pluggable authentication through the MIT Kerberos library on Windows |
| --插件目录--plugin-dir | 插件安装的目录Directory where plugins are installed |
| --端口--port | 连接的 TCP/IP 端口号TCP/IP port number for connection |
| --打印默认值--print-defaults | 打印默认选项Print default options |
| --协议--protocol | 要使用的传输协议Transport 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 | 编写 REPLACE 语句而不是 INSERT 语句Write REPLACE statements rather than INSERT statements |
| --结果文件--result-file | 直接输出到给定文件Direct output to a given file |
| --例程--routines | 从转储数据库转储存储例程(过程和函数)Dump stored routines (procedures and functions) from dumped databases |
| --服务器公钥路径--server-public-key-path | 包含 RSA 公钥的文件路径名称Path name to file containing RSA public key |
| --设置字符集--set-charset | 将 SET NAMES default_character_set 添加到输出Add SET NAMES default_character_set to output |
| --设置已清除 GTID--set-gtid-purged | 是否在输出中添加 SET @@GLOBAL.GTID_PURGEDWhether to add SET @@GLOBAL.GTID_PURGED to output |
| --共享内存基础名称--shared-memory-base-name | 共享内存连接的共享内存名称(仅限 Windows)Shared-memory name for shared-memory connections (Windows only) |
| --显示创建时跳过二级引擎--show-create-skip-secondary-engine | 从 CREATE TABLE 语句中排除 SECONDARY ENGINE 子句Exclude SECONDARY ENGINE clause from CREATE TABLE statements |
| --单事务--single-transaction | 在从服务器转储数据之前发出 BEGIN SQL 语句Issue a BEGIN SQL statement before dumping data from server |
| --跳过添加删除表--skip-add-drop-table | 不要在每个 CREATE TABLE 语句之前添加 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 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-generated-invisible-primary-key | 不要在转储文件中包含生成的不可见主键Do not include generated invisible primary keys in dump file |
| --跳过优化选项--skip-opt | 关闭--opt 设置的选项Turn off 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 | 不要写 SET NAMES 语句Do not write SET NAMES statement |
| --跳过触发器--skip-triggers | 不要转储触发器Do not dump triggers |
| --跳过时区 UTC--skip-tz-utc | 关闭 tz-utcTurn off tz-utc |
| --套接字--socket | 要使用的 Unix 套接字文件或 Windows 命名管道Unix socket file or Windows named pipe to use |
| --源数据--source-data | 将二进制日志文件名和位置写入输出Write the binary log file name and position to the output |
| --SSL CA 证书--ssl-ca | 包含受信任的 SSL 证书颁发机构列表的文件File that contains list of trusted SSL Certificate Authorities |
| --SSL CA 路径--ssl-capath | 包含受信任的 SSL 证书颁发机构证书文件的目录Directory that contains trusted SSL Certificate Authority certificate files |
| --SSL 证书--ssl-cert | 包含 X.509 证书的文件File that contains X.509 certificate |
| --SSL 加密套件--ssl-cipher | 连接加密的允许密码Permissible ciphers for connection encryption |
| --ssl-crl | 包含证书吊销列表的文件File that contains certificate revocation lists |
| --SSL CRL 路径--ssl-crlpath | 包含证书吊销列表文件的目录Directory that contains certificate revocation-list files |
| --SSL FIPS 模式--ssl-fips-mode | 是否在客户端启用 FIPS 模式Whether to enable FIPS mode on client side |
| --ssl-密钥--ssl-key | 包含 X.509 密钥的文件File that contains X.509 key |
| --ssl-模式--ssl-mode | 与服务器连接的期望安全状态Desired security state of connection to server |
| --ssl-会话数据--ssl-session-data | 包含 SSL 会话数据的文件File that contains SSL session data |
| --ssl-会话数据-失败重用继续--ssl-session-data-continue-on-failed-reuse | 如果会话重用失败,是否建立连接Whether to establish connections if session reuse fails |
| --制表符--tab | 生成制表符分隔的数据文件Produce tab-separated data files |
| --表--tables | 覆盖 --databases 或 -B 选项Override --databases or -B option |
| --tls-密码套件--tls-ciphersuites | 允许的用于加密连接的 TLSv1.3 加密套件Permissible TLSv1.3 ciphersuites for encrypted connections |
| --tls-sni-服务器名称--tls-sni-servername | 由客户端提供的服务器名称Server name supplied by the client |
| --tls-版本--tls-version | 允许用于加密连接的 TLS 协议Permissible TLS protocols for encrypted connections |
| --触发器--triggers | 每个转储表的转储触发器Dump triggers for each dumped table |
| --时区-UTC--tz-utc | 添加 SET TIME_ZONE='+00:00' 到转储文件Add SET TIME_ZONE='+00:00' to dump file |
| --用户--user | 连接服务器时使用的 MySQL 用户名MySQL user name to use when connecting to server |
| --详细--verbose | 详细模式Verbose mode |
| --版本--version | 显示版本信息并退出Display version information and exit |
| --哪里--where | 仅转储由给定 WHERE 条件选择的行Dump only rows selected by given WHERE condition |
| --xml | 生成 XML 输出Produce XML output |
| --zstd-压缩等级--zstd-compression-level | 用于与服务器进行 zstd 压缩连接的压缩级别Compression level for connections to server that use zstd compression |
连接选项Connection Options
mysqldump 命令登录 MySQL 服务器以提取信息。以下选项指定如何连接到同一计算机或远程系统上的 MySQL 服务器。The mysqldump command logs into a MySQL server to extract information. The following options specify how to connect to the MySQL server, either on the same machine or a remote system.
命令行格式Command-Line Format --bind-address=ip_address--bind-address=ip_address在具有多个网络接口的计算机上,使用此选项选择用于连接到 MySQL 服务器的接口。On a computer having multiple network interfaces, use this option to select which interface to use for connecting to the MySQL server.
--compress,-C命令行格式Command-Line Format --compress[={OFF|ON}]--compress[={OFF|ON}]已弃用Deprecated 是Yes 类型Type 布尔Boolean 默认值Default Value OFFOFF如果可能,压缩客户端与服务器之间发送的所有信息。参见 第 6.2.8 节,“连接压缩控制”。Compress all information sent between the client and the server if possible. See Section 6.2.8, “Connection Compression Control”.
此选项已被弃用。预计将在 MySQL 的未来版本中移除。请参阅 配置遗留连接压缩。This option is deprecated. Expect it to be removed in a future version of MySQL. See Configuring Legacy Connection Compression.
--compression-algorithms=value--compression-algorithms=value命令行格式Command-Line Format --compression-algorithms=value--compression-algorithms=value类型Type 设置Set 默认值Default Value uncompresseduncompressed有效值Valid Values zlibzstduncompresseduncompressed允许用于与服务器连接的压缩算法。可用算法与
protocol_compression_algorithms系统变量的算法相同。默认值为uncompressed。The permitted compression algorithms for connections to the server. The available algorithms are the same as for theprotocol_compression_algorithmssystem variable. The default value isuncompressed.更多信息,请参阅 第 6.2.8 节,“连接压缩控制”。For more information, see Section 6.2.8, “Connection Compression Control”.
--default-auth=plugin--default-auth=plugin命令行格式Command-Line Format --default-auth=plugin--default-auth=plugin类型Type 字符串String 关于使用哪种客户端身份验证插件的提示。请参见 第 8.2.17 节,“可插拔身份验证”。A hint about which client-side authentication plugin to use. See Section 8.2.17, “Pluggable Authentication”.
命令行格式Command-Line Format --enable-cleartext-plugin类型Type 布尔Boolean 默认值Default Value FALSE启用
mysql_clear_password明文身份验证插件。(参见 第 8.4.1.4 节,“客户端明文可插拔身份验证”。)Enable themysql_clear_passwordcleartext authentication plugin. (See Section 8.4.1.4, “Client-Side Cleartext Pluggable Authentication”.)命令行格式Command-Line Format --get-server-public-key--get-server-public-key类型Type 布尔Boolean 向服务器请求用于基于 RSA 密钥对的密码交换所需的公钥。此选项适用于使用
caching_sha2_password身份验证插件进行身份验证的客户端。对于该插件,服务器不会发送公钥,除非被请求。对于未使用该插件进行身份验证的账户,此选项将被忽略。当未使用基于 RSA 的密码交换时(例如客户端使用安全连接连接服务器时),此选项也将被忽略。Request from the server the public key required for RSA key pair-based password exchange. This option applies to clients that authenticate with thecaching_sha2_passwordauthentication plugin. For that plugin, the server does not send the public key unless requested. This option is ignored for accounts that do not authenticate with that plugin. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.如果
--server-public-key-path=已给出并指定有效的公钥文件,它优先于file_name--get-server-public-key。If--server-public-key-path=is given and specifies a valid public key file, it takes precedence overfile_name--get-server-public-key.有关
caching_sha2_password插件的信息,请参见 第 8.4.1.2 节,“缓存 SHA-2 可插拔认证”。For information about thecaching_sha2_passwordplugin, see Section 8.4.1.2, “Caching SHA-2 Pluggable Authentication”.--host=host_name,-h host_name--host=,host_name-hhost_name命令行格式Command-Line Format --host--host从给定的 MySQL 服务器转储数据主机。默认主机为
localhost。Dump data from the MySQL server on the given host. The default host islocalhost.--login-path=name--login-path=name命令行格式Command-Line Format --login-path=name--login-path=name类型Type 字符串String 从名为登录路径的
.mylogin.cnf登录路径文件中读取选项。“登录路径” 是一个选项组,包含指定要连接哪个 MySQL 服务器以及以哪个帐户进行身份验证的选项。要创建或修改登录路径文件,请使用 mysql_config_editor 工具。参见 第 6.6.7 节,“mysql_config_editor — MySQL 配置工具”。Read options from the named login path in the.mylogin.cnflogin path file. A “login path” is an option group containing options that specify which MySQL server to connect to and which account to authenticate as. To create or modify a login path file, use the mysql_config_editor utility. See Section 6.6.7, “mysql_config_editor — MySQL Configuration Utility”.有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
命令行格式Command-Line Format --no-login-paths跳过从登录路径文件读取选项。Skips reading options from the login path file.
相关内容参见
--login-path信息。See--login-pathfor related information.有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
--password[=password],-p[password]--password[=,password]-p[password]命令行格式Command-Line Format --password[=password]--password[=password]类型Type 字符串String 用于连接服务器的 MySQL 帐户的密码。密码值是可选的。如果未给出,mysqldump 会提示输入一个。如果给出,
--password=或-p与其后面的密码之间必须没有空格。如果未指定密码选项,则默认不发送密码。The password of the MySQL account used for connecting to the server. The password value is optional. If not given, mysqldump prompts for one. If given, there must be no space between--password=or-pand the password following it. If no password option is specified, the default is to send no password.在命令行中指定密码应被视为不安全。为了避免在命令行中输入密码,请使用选项文件。请参阅 第 8.1.2.1 节,“终端用户密码安全指南”。Specifying a password on the command line should be considered insecure. To avoid giving the password on the command line, use an option file. See Section 8.1.2.1, “End-User Guidelines for Password Security”.
要显式指定没有密码并且mysqldump 不应提示输入密码,请使用
--skip-password选项。To explicitly specify that there is no password and that mysqldump should not prompt for one, use the--skip-passwordoption.多重身份验证因素的密码 1 用于连接服务器的 MySQL 帐户。密码值是可选的。如果未给出,mysqldump 会提示输入一个。如果给出,
--password1=与其后面的密码之间必须没有空格。如果未指定密码选项,则默认不发送密码。The password for multifactor authentication factor 1 of the MySQL account used for connecting to the server. The password value is optional. If not given, mysqldump prompts for one. If given, there must be no space between--password1=and the password following it. If no password option is specified, the default is to send no password.在命令行中指定密码应被视为不安全。为了避免在命令行中输入密码,请使用选项文件。请参阅 第 8.1.2.1 节,“终端用户密码安全指南”。Specifying a password on the command line should be considered insecure. To avoid giving the password on the command line, use an option file. See Section 8.1.2.1, “End-User Guidelines for Password Security”.
要显式指定没有密码并且mysqldump 不应提示输入密码,请使用
--skip-password1选项。To explicitly specify that there is no password and that mysqldump should not prompt for one, use the--skip-password1option.--password1和--password是同义词,--skip-password1和--skip-password。--password1and--passwordare synonymous, as are--skip-password1and--skip-password.用于连接服务器的 MySQL 帐户的多重身份验证因子 2 的密码。该选项的语义类似于
--password1的语义;有关详细信息,请参阅该选项的说明。The password for multifactor authentication factor 2 of the MySQL account used for connecting to the server. The semantics of this option are similar to the semantics for--password1; see the description of that option for details.用于连接的 MySQL 帐户的多重身份验证因子 3 的密码服务器。该选项的语义类似于
--password1的语义;有关详细信息,请参阅该选项的说明。The password for multifactor authentication factor 3 of the MySQL account used for connecting to the server. The semantics of this option are similar to the semantics for--password1; see the description of that option for details.--pipe,-W命令行格式Command-Line Format --pipe类型Type 字符串String 在 Windows 上,通过命名管道连接到服务器。此选项仅在服务器启动时已启用
named_pipe系统变量以支持命名管道连接的情况下适用。此外,进行连接的用户必须是由named_pipe_full_access_group系统变量指定的 Windows 组的成员。On Windows, connect to the server using a named pipe. This option applies only if the server was started with thenamed_pipesystem variable enabled to support named-pipe connections. In addition, the user making the connection must be a member of the Windows group specified by thenamed_pipe_full_access_groupsystem variable.--plugin-authentication-kerberos-client-mode=value--plugin-authentication-kerberos-client-mode=value命令行格式Command-Line Format --plugin-authentication-kerberos-client-mode类型Type 字符串String 默认值Default Value SSPI有效值Valid Values GSSAPI在 Windows 上,
authentication_kerberos_client身份验证插件支持此插件选项。它提供了客户端用户可以在运行时设置的两个可能值:SSPI和GSSAPI。On Windows, theauthentication_kerberos_clientauthentication plugin supports this plugin option. It provides two possible values that the client user can set at runtime:SSPIandGSSAPI.客户端插件选项的默认值使用安全支持提供程序接口 (SSPI),该接口能够从 Windows 内存缓存中获取凭据。或者,客户端用户可以通过 Windows 上的 MIT Kerberos 库选择支持通用安全服务应用程序接口 (GSSAPI) 的模式。 GSSAPI 能够获取之前使用 kinit 命令生成的缓存凭据。The default value for the client-side plugin option uses Security Support Provider Interface (SSPI), which is capable of acquiring credentials from the Windows in-memory cache. Alternatively, the client user can select a mode that supports Generic Security Service Application Program Interface (GSSAPI) through the MIT Kerberos library on Windows. GSSAPI is capable of acquiring cached credentials previously generated by using the kinit command.
有关详细信息,请参阅GSSAPI 模式下 Windows 客户端的命令。For more information, see Commands for Windows Clients in GSSAPI Mode.
--plugin-dir=dir_name--plugin-dir=dir_name命令行格式Command-Line Format --plugin-dir=dir_name--plugin-dir=dir_name类型Type 目录名称Directory name 查找插件的目录。如果使用
--default-auth选项指定身份验证插件,但 mysqldump 找不到它,请指定此选项。请参阅第 8.2.17 节“可插入身份验证”。The directory in which to look for plugins. Specify this option if the--default-authoption is used to specify an authentication plugin but mysqldump does not find it. See Section 8.2.17, “Pluggable Authentication”.--port=port_num,-P port_num--port=,port_num-Pport_num命令行格式Command-Line Format --port=port_num--port=port_num类型Type 数字Numeric 默认值Default Value 3306对于 TCP/IP 连接,要使用的端口号。For TCP/IP connections, the port number to use.
--protocol={TCP|SOCKET|PIPE|MEMORY}命令行格式Command-Line Format --protocol=type--protocol=type类型Type 字符串String 默认值Default Value [see text][see text]有效值Valid Values TCPSOCKETSOCKETPIPEPIPEMEMORYMEMORY用于连接服务器的传输协议。当其他连接参数通常导致使用的协议不是您想要的协议时,这很有用。有关允许值的详细信息,请参阅第 6.2.7 节,“连接传输协议”。The transport protocol to use for connecting to the server. It is useful when the other connection parameters normally result in use of a protocol other than the one you want. For details on the permissible values, see Section 6.2.7, “Connection Transport Protocols”.
--server-public-key-path=file_name--server-public-key-path=file_name命令行格式Command-Line Format --server-public-key-path=file_name--server-public-key-path=file_name类型Type 文件名File name 包含服务器所需的 RSA 密钥对密码交换的客户端副本公钥的 PEM 格式文件的路径名。此选项适用于使用
sha256_password(已弃用)或caching_sha2_password身份验证插件进行身份验证的客户端。对于不使用这些插件之一进行身份验证的帐户,将忽略此选项。如果未使用基于 RSA 的密码交换(例如客户端使用安全连接连接到服务器的情况),此选项也将被忽略。The path name to a file in PEM format containing a client-side copy of the public key required by the server for RSA key pair-based password exchange. This option applies to clients that authenticate with thesha256_password(deprecated) orcaching_sha2_passwordauthentication plugin. This option is ignored for accounts that do not authenticate with one of those plugins. It is also ignored if RSA-based password exchange is not used, as is the case when the client connects to the server using a secure connection.如果
--server-public-key-path=已给出并指定有效的公钥文件,它优先于file_name--get-server-public-key。If--server-public-key-path=is given and specifies a valid public key file, it takes precedence overfile_name--get-server-public-key.对于
sha256_password(已弃用),此选项仅在 MySQL 使用 OpenSSL 构建时才适用。Forsha256_password(deprecated), this option applies only if MySQL was built using OpenSSL.有关
sha256_password和caching_sha2_password插件的信息,请参见 第 8.4.1.3 节,“SHA-256 可插拔认证” 和 第 8.4.1.2 节,“缓存 SHA-2 可插拔认证”。For information about thesha256_passwordandcaching_sha2_passwordplugins, see Section 8.4.1.3, “SHA-256 Pluggable Authentication”, and Section 8.4.1.2, “Caching SHA-2 Pluggable Authentication”.--socket=path,-S path--socket=,path-Spath命令行格式Command-Line Format --socket={file_name|pipe_name}--socket={file_name|pipe_name}类型Type 字符串String 用于连接
localhost时,使用的 Unix 套接字文件,或者在 Windows 上使用的命名管道的名称。For connections tolocalhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.在 Windows 上,此选项仅在服务器启用支持命名管道连接的
named_pipe系统变量启动时才适用。此外,进行连接的用户必须是由named_pipe_full_access_group系统变量指定的 Windows 组的成员。On Windows, this option applies only if the server was started with thenamed_pipesystem variable enabled to support named-pipe connections. In addition, the user making the connection must be a member of the Windows group specified by thenamed_pipe_full_access_groupsystem variable.以
--ssl开头的选项指定是否使用加密连接到服务器,并指示在哪里可以找到 SSL 密钥和证书。请参阅 加密连接的命令选项。Options that begin with--sslspecify whether to connect to the server using encryption and indicate where to find SSL keys and certificates. See Command Options for Encrypted Connections.--ssl-fips-mode={OFF|ON|STRICT}命令行格式Command-Line Format --ssl-fips-mode={OFF|ON|STRICT}--ssl-fips-mode={OFF|ON|STRICT}已弃用Deprecated 是Yes 类型Type 枚举Enumeration 默认值Default Value OFFOFF有效值Valid Values OFFOFFONONSTRICTSTRICT控制是否在客户端启用 FIPS 模式。
--ssl-fips-mode选项与其他--ssl-选项不同,因为它不用于建立加密连接,而是用于影响允许哪些加密操作。请参阅第 8.8 节“FIPS 支持”。Controls whether to enable FIPS mode on the client side. Thexxx--ssl-fips-modeoption differs from other--ssl-options in that it is not used to establish encrypted connections, but rather to affect which cryptographic operations to permit. See Section 8.8, “FIPS Support”.xxx这些
--ssl-fips-mode值是允许的:These--ssl-fips-modevalues are permitted:OFF:禁用 FIPS 模式。OFF: Disable FIPS mode.ON:启用 FIPS 模式。ON: Enable FIPS mode.STRICT:启用“严格” FIPS 模式。STRICT: Enable “strict” FIPS mode.
Note如果 OpenSSL FIPS 对象模块是不可用,
--ssl-fips-mode唯一允许的值为OFF。在这种情况下,将--ssl-fips-mode设置为ON或STRICT会导致客户端在启动时生成警告并在非 FIPS 模式下运行。If the OpenSSL FIPS Object Module is not available, the only permitted value for--ssl-fips-modeisOFF. In this case, setting--ssl-fips-modetoONorSTRICTcauses the client to produce a warning at startup and to operate in non-FIPS mode.此选项已弃用。预计将在未来的 MySQL 版本中移除。This option is deprecated. Expect it to be removed in a future version of MySQL.
--tls-ciphersuites=ciphersuite_list命令行格式Command-Line Format --tls-ciphersuites=ciphersuite_list--tls-ciphersuites=ciphersuite_list类型Type 字符串String 用于 TLSv1.3 加密连接的允许密码套件。该值是一个或多个用冒号分隔的密码套件名称的列表。此选项可指定的密码套件取决于用于编译 MySQL 的 SSL 库。有关详细信息,请参见 第 8.3.2 节,“加密连接的 TLS 协议和密码”。The permissible ciphersuites for encrypted connections that use TLSv1.3. The value is a list of one or more colon-separated ciphersuite names. The ciphersuites that can be named for this option depend on the SSL library used to compile MySQL. For details, see Section 8.3.2, “Encrypted Connection TLS Protocols and Ciphers”.
--tls-sni-servername=server_name命令行格式Command-Line Format --tls-sni-servername=server_name--tls-sni-servername=server_name类型Type 字符串String 如果指定了名称,该名称将通过
mysql_options()的MYSQL_OPT_TLS_SNI_SERVERNAME选项传递给libmysqlclientC API 库。服务器名称不区分大小写。要显示客户端为当前会话指定的服务器名称(如果有),请检查Tls_sni_server_name状态变量。When specified, the name is passed to thelibmysqlclientC API library using theMYSQL_OPT_TLS_SNI_SERVERNAMEoption ofmysql_options(). The server name is not case-sensitive. To show which server name the client specified for the current session, if any, check theTls_sni_server_namestatus variable.服务器名称指示(SNI)是 TLS 协议的一个扩展(必须使用支持 TLS 扩展的 OpenSSL 编译此选项才能生效)。MySQL 对 SNI 的实现仅代表客户端。Server Name Indication (SNI) is an extension to the TLS protocol (OpenSSL must be compiled using TLS extensions for this option to function). The MySQL implementation of SNI represents the client-side only.
命令行格式Command-Line Format --tls-version=protocol_list--tls-version=protocol_list类型Type 字符串String 默认值Default Value TLSv1,TLSv1.1,TLSv1.2,TLSv1.3(OpenSSL 1.1.1 或更高版本)TLSv1,TLSv1.1,TLSv1.2,TLSv1.3(OpenSSL 1.1.1 or higher)TLSv1,TLSv1.1,TLSv1.2(否则)TLSv1,TLSv1.1,TLSv1.2(otherwise)用于加密连接的允许 TLS 协议。值是一个或多个以逗号分隔的协议名称列表。此选项可指定的协议取决于用于编译 MySQL 的 SSL 库。详情请参见 第 8.3.2 节,“加密连接 TLS 协议和密码”。The permissible TLS protocols for encrypted connections. The value is a list of one or more comma-separated protocol names. The protocols that can be named for this option depend on the SSL library used to compile MySQL. For details, see Section 8.3.2, “Encrypted Connection TLS Protocols and Ciphers”.
--user=user_name,-u user_name--user=,user_name-uuser_name命令行格式Command-Line Format --user=user_name--user=user_name类型Type 字符串String 用于连接服务器的 MySQL 帐户用户名。The user name of the MySQL account to use for connecting to the server.
如果您使用
Rewriter插件,则应授予此用户SKIP_QUERY_REWRITE权限。If you are using theRewriterplugin, you should grant this user theSKIP_QUERY_REWRITEprivilege.--zstd-compression-level=level--zstd-compression-level=level命令行格式Command-Line Format --zstd-compression-level=#类型Type 整数Integer 用于与服务器连接时使用
zstd压缩算法的压缩级别。允许的级别从 1 到 22,数值越大表示压缩级别越高。默认的zstd压缩级别为 3。对于不使用zstd压缩的连接,压缩级别设置没有效果。The compression level to use for connections to the server that use thezstdcompression algorithm. The permitted levels are from 1 to 22, with larger values indicating increasing levels of compression. The defaultzstdcompression level is 3. The compression level setting has no effect on connections that do not usezstdcompression.更多信息,请参阅 第 6.2.8 节,“连接压缩控制”。For more information, see Section 6.2.8, “Connection Compression Control”.
选项文件选项Option-File Options
这些选项用于控制读取哪些选项文件。These options are used to control which option files to read.
--defaults-extra-file=file_name--defaults-extra-file=file_name命令行格式Command-Line Format --defaults-extra-file=file_name--defaults-extra-file=file_name类型Type 文件名File name 在全局选项文件之后读取此选项文件,但(在 Unix 系统上)在用户选项文件之前。如果该文件不存在或无法访问,将发生错误。如果
file_name不是绝对路径名,则相对于当前目录解释。Read this option file after the global option file but (on Unix) before the user option file. If the file does not exist or is otherwise inaccessible, an error occurs. Iffile_nameis not an absolute path name, it is interpreted relative to the current directory.有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
--defaults-file=file_name--defaults-file=file_name命令行格式Command-Line Format --defaults-file=file_name--defaults-file=file_name类型Type 文件名File name 仅使用指定的选项文件。如果文件不存在或无法访问,将会发生错误。如果
file_name不是绝对路径名,则将其相对于当前目录解释。Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs. Iffile_nameis not an absolute path name, it is interpreted relative to the current directory.例外:即使使用
--defaults-file,客户端程序仍会读取.mylogin.cnf。Exception: Even with--defaults-file, client programs read.mylogin.cnf.有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
--defaults-group-suffix=str--defaults-group-suffix=str命令行格式Command-Line Format --defaults-group-suffix=str--defaults-group-suffix=str类型Type 字符串String 不仅读取常用选项组,还读取具有常用名称和后缀
str的组。例如,mysqldump 通常读取[client]和[mysqldump]组。如果此选项指定为--defaults-group-suffix=_other,则 mysqldump 也会读取[client_other]和[mysqldump_other]组。Read not only the usual option groups, but also groups with the usual names and a suffix ofstr. For example, mysqldump normally reads the[client]and[mysqldump]groups. If this option is given as--defaults-group-suffix=_other, mysqldump also reads the[client_other]and[mysqldump_other]groups.有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
命令行格式Command-Line Format --no-defaults--no-defaults不读取任何选项文件。如果由于从选项文件中读取未知选项而导致程序启动失败,可以使用
--no-defaults来阻止读取它们。Do not read any option files. If program startup fails due to reading unknown options from an option file,--no-defaultscan be used to prevent them from being read.例外是
.mylogin.cnf文件(如果存在)在所有情况下都会被读取。即使使用--no-defaults,这也允许以比命令行更安全的方式指定密码。要创建.mylogin.cnf,请使用 mysql_config_editor 实用程序。请参阅第 6.6.7 节“mysql_config_editor — MySQL 配置实用程序”。The exception is that the.mylogin.cnffile is read in all cases, if it exists. This permits passwords to be specified in a safer way than on the command line even when--no-defaultsis used. To create.mylogin.cnf, use the mysql_config_editor utility. See Section 6.6.7, “mysql_config_editor — MySQL Configuration Utility”.有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
命令行格式Command-Line Format --print-defaults打印程序名称以及它从选项文件中获取的所有选项。Print the program name and all options that it gets from option files.
有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
DDL 选项DDL Options
mysqldump 的使用场景包括设置全新的 MySQL 实例(包括表),以及用现有数据库和表替换现有实例中的数据。以下选项可让您通过在转储文件中编码各种 DDL 语句来指定恢复转储时要拆除和设置的内容。Usage scenarios for mysqldump include setting up an entire new MySQL instance (including database tables), and replacing data inside an existing instance with existing databases and tables. The following options let you specify which things to tear down and set up when restoring a dump, by encoding various DDL statements within the dump file.
命令行格式Command-Line Format --add-drop-database--add-drop-databaseWrite a
DROP DATABASEstatement before eachCREATE DATABASEstatement. This option is typically used in conjunction with the--all-databases或者--databasesoption because noCREATE DATABASEstatements are written unless one of those options is specified.Write aDROP DATABASEstatement before eachCREATE DATABASEstatement. This option is typically used in conjunction with the--all-databasesor--databasesoption because noCREATE DATABASEstatements are written unless one of those options is specified.Note在 MySQL 8.4 中,
mysql架构被视为最终用户无法删除的系统架构。如果--add-drop-database与--all-databases或--databases其中要转储的架构列表包括mysql,转储文件包含DROP DATABASE `mysql`语句,该语句在重新加载转储文件时会导致错误。In MySQL 8.4, themysqlschema is considered a system schema that cannot be dropped by end users. If--add-drop-databaseis used with--all-databasesor with--databaseswhere the list of schemas to be dumped includesmysql, the dump file contains aDROP DATABASE `mysql`statement that causes an error when the dump file is reloaded.相反,应使用
--add-drop-database,使用--databases以及要转储的架构列表,其中该列表不包括mysql。Instead, to use--add-drop-database, use--databaseswith a list of schemas to be dumped, where the list does not includemysql.命令行格式Command-Line Format --add-drop-table--add-drop-table写一个
DROP TABLE语句位于每个CREATE TABLE语句之前。Write aDROP TABLEstatement before eachCREATE TABLEstatement.命令行格式Command-Line Format --add-drop-trigger--add-drop-trigger编写一个
DROP TRIGGER语句位于每个CREATE TRIGGER语句之前。Write aDROP TRIGGERstatement before eachCREATE TRIGGERstatement.命令行格式Command-Line Format --all-tablespaces将创建所使用的任何表空间所需的所有 SQL 语句添加到表转储中通过
NDB表。此信息不会以其他方式包含在 mysqldump 的输出中。此选项目前仅与 NDB Cluster 表相关。Adds to a table dump all SQL statements needed to create any tablespaces used by anNDBtable. This information is not otherwise included in the output from mysqldump. This option is currently relevant only to NDB Cluster tables.--no-create-db,-n命令行格式Command-Line Format --no-create-dbSuppress the
CREATE DATABASEstatements that are otherwise included in the output if the--databases或者--all-databasesoption is given.Suppress theCREATE DATABASEstatements that are otherwise included in the output if the--databasesor--all-databasesoption is given.--no-create-info,-t命令行格式Command-Line Format --no-create-info不要编写创建每个转储的
CREATE TABLE语句Do not writeCREATE TABLEstatements that create each dumped table.Note此选项不从mysqldump 输出中排除创建日志文件组或表空间的语句;但是,您可以使用
--no-tablespaces选项来实现此目的。This option does not exclude statements creating log file groups or tablespaces from mysqldump output; however, you can use the--no-tablespacesoption for this purpose.--no-tablespaces,-y--no-tablespaces,-y命令行格式Command-Line Format --no-tablespaces--no-tablespaces此选项禁止所有
CREATE LOGFILE GROUP和CREATE TABLESPACE语句。This option suppresses allCREATE LOGFILE GROUPandCREATE TABLESPACEstatements in the output of mysqldump.命令行格式Command-Line Format --replace--replace编写
REPLACE语句而不是INSERT语句。WriteREPLACEstatements rather thanINSERTstatements.
调试选项Debug Options
以下选项打印调试信息,在转储文件中编码调试信息,或者让转储操作继续进行,而不管潜在的问题。The following options print debugging information, encode debugging information in the dump file, or let the dump operation proceed regardless of potential problems.
命令行格式Command-Line Format --allow-keywords允许创建作为关键字的列名称。这是通过在每个列名前加上表名来实现的。Permit creation of column names that are keywords. This works by prefixing each column name with the table name.
--comments,-i命令行格式Command-Line Format --comments在转储文件中写入附加信息,例如程序版本、服务器版本和主机。默认情况下启用此选项。要隐藏此附加信息,请使用
--skip-comments。Write additional information in the dump file such as program version, server version, and host. This option is enabled by default. To suppress this additional information, use--skip-comments.--debug[=,debug_options]-# [debug_options]命令行格式Command-Line Format --debug[=debug_options]--debug[=debug_options]类型Type 字符串String 默认值Default Value d:t:o,/tmp/mysqldump.trace写入调试日志。典型的
debug_options字符串是d:t:o,。默认值为file_named:t:o,/tmp/mysqldump.trace。Write a debugging log. A typicaldebug_optionsstring isd:t:o,. The default value isfile_named:t:o,/tmp/mysqldump.trace.此选项仅在 MySQL 使用
WITH_DEBUG构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built usingWITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.命令行格式Command-Line Format --debug-check类型Type 布尔Boolean 默认值Default Value FALSE程序退出时打印一些调试信息。Print some debugging information when the program exits.
此选项仅在 MySQL 使用
WITH_DEBUG构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built usingWITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.命令行格式Command-Line Format --debug-info类型Type 布尔Boolean 默认值Default Value FALSE在程序退出时打印调试信息以及内存和 CPU 使用情况统计。Print debugging information and memory and CPU usage statistics when the program exits.
此选项仅在 MySQL 使用
WITH_DEBUG构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built usingWITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.命令行格式Command-Line Format --dump-date类型Type 布尔Boolean 默认值Default Value TRUE如果给出
--comments选项,mysqldump 在转储末尾生成以下形式的注释:If the--commentsoption is given, mysqldump produces a comment at the end of the dump of the following form:-- Dump completed on
DATE但是,日期会导致不同时间获取的转储文件看起来不同,即使数据在其他方面相同。
--dump-date和--skip-dump-date控制是否将日期添加到注释中。默认值为--dump-date(在注释中包含日期)。--skip-dump-date禁止打印日期。However, the date causes dump files taken at different times to appear to be different, even if the data are otherwise identical.--dump-dateand--skip-dump-datecontrol whether the date is added to the comment. The default is--dump-date(include the date in the comment).--skip-dump-datesuppresses date printing.--force,-f命令行格式Command-Line Format --force忽略所有错误;即使在表转储期间发生 SQL 错误,也可以继续。Ignore all errors; continue even if an SQL error occurs during a table dump.
此选项的一个用途是使 mysqldump 继续执行,即使它遇到因定义引用已删除的表而变得无效的视图。如果没有
--force,mysqldump 将退出并显示错误消息。使用--force,mysqldump 打印错误消息,但它还会将包含视图定义的 SQL 注释写入转储输出并继续执行。One use for this option is to cause mysqldump to continue executing even when it encounters a view that has become invalid because the definition refers to a table that has been dropped. Without--force, mysqldump exits with an error message. With--force, mysqldump prints the error message, but it also writes an SQL comment containing the view definition to the dump output and continues executing.如果
--ignore-error选项还可以忽略特定错误,--force优先。If the--ignore-erroroption is also given to ignore specific errors,--forcetakes precedence.--log-error=file_name--log-error=file_name命令行格式Command-Line Format --log-error=file_name--log-error=file_name类型Type 文件名File name 通过将警告和错误附加到指定文件来记录它们。默认情况下不进行日志记录。Log warnings and errors by appending them to the named file. The default is to do no logging.
命令行格式Command-Line Format --skip-comments请参阅
--comments选项。See the description for the--commentsoption.--verbose,-v命令行格式Command-Line Format --verbose--verbose详细模式。打印有关程序执行内容的更多信息。Verbose mode. Print more information about what the program does.
帮助选项Help Options
以下选项显示有关mysqldump 命令本身的信息。The following options display information about the mysqldump command itself.
国际化选项Internationalization Options
以下选项更改mysqldump 命令表示具有国家语言设置的字符数据的方式。The following options change how the mysqldump command represents character data with national language settings.
--character-sets-dir=dir_name--character-sets-dir=dir_name命令行格式Command-Line Format --character-sets-dir=dir_name--character-sets-dir=dir_name类型Type 目录名称Directory name 安装字符集的目录。请参见第 12.15 节,“字符集配置”。The directory where character sets are installed. See Section 12.15, “Character Set Configuration”.
--default-character-set=charset_name--default-character-set=charset_name命令行格式Command-Line Format --default-character-set=charset_name--default-character-set=charset_name类型Type 字符串String 默认值Default Value utf8使用
charset_name作为默认字符集。请参见第 12.15 节“字符集配置”。如果未指定字符集,mysqldump 使用utf8mb4。Usecharset_nameas the default character set. See Section 12.15, “Character Set Configuration”. If no character set is specified, mysqldump usesutf8mb4.--no-set-names,-N命令行格式Command-Line Format --no-set-names已弃用Deprecated 是Yes 关闭
--set-charset设置,与指定--skip-set-charset相同。Turns off the--set-charsetsetting, the same as specifying--skip-set-charset.命令行格式Command-Line Format --set-charset禁用者Disabled by skip-set-charset将
SET NAMES default_character_set写入输出。默认情况下启用此选项。要禁止使用SET NAMES语句,请使用--skip-set-charset。WriteSET NAMESto the output. This option is enabled by default. To suppress thedefault_character_setSET NAMESstatement, use--skip-set-charset.
复制选项Replication Options
mysqldump 命令经常用于在复制配置中的副本服务器上创建空实例或包含数据的实例。以下选项适用于在复制源服务器和副本上转储和恢复数据。The mysqldump command is frequently used to create an empty instance, or an instance including data, on a replica server in a replication configuration. The following options apply to dumping and restoring data on replication source servers and replicas.
命令行格式Command-Line Format --apply-replica-statements类型Type 布尔Boolean 默认值Default Value FALSE对于使用
--dump-replica选项生成的副本转储,此选项添加STOP REPLICA语句位于带有二进制日志坐标的语句之前,START REPLICA语句位于输出末尾。For a replica dump produced with the--dump-replicaoption, this option adds aSTOP REPLICAstatement before the statement with the binary log coordinates, and aSTART REPLICAstatement at the end of the output.命令行格式Command-Line Format --apply-slave-statements已弃用Deprecated 是Yes 类型Type 布尔Boolean 默认值Default Value FALSE这是
--apply-replica-statements。This is a deprecated alias for--apply-replica-statements.命令行格式Command-Line Format --delete-source-logs在复制源服务器上,通过发送
PURGE BINARY LOGS语句。这些选项需要RELOAD权限以及足以执行该语句的权限。此选项自动启用--source-data。On a replication source server, delete the binary logs by sending aPURGE BINARY LOGSstatement to the server after performing the dump operation. The options require theRELOADprivilege as well as privileges sufficient to execute that statement. This option automatically enables--source-data.命令行格式Command-Line Format --delete-master-logs已弃用Deprecated 是Yes 这是
--delete-source-logs。This is a deprecated alias for--delete-source-logs.--dump-replica[=value]--dump-replica[=value]命令行格式Command-Line Format --dump-replica[=value]类型Type 数字Numeric 默认值Default Value 1有效值Valid Values 12This option is similar to
--source-data, except that it is used to dump a replica server to produce a dump file that can be used to set up another server as a replica that has the same source as the dumped server. The option causes the dump output to include aCHANGE REPLICATION SOURCE TOstatement that indicates the binary log coordinates (file name and position) of the dumped replica's source. TheCHANGE REPLICATION SOURCE TOstatement reads the values ofRelay_Master_Log_File以及Exec_Master_Log_Posfrom theSHOW REPLICA STATUSoutput and uses them forSOURCE_LOG_FILE以及SOURCE_LOG_POSrespectively. These are the replication source server coordinates from which the replica starts replicating.This option is similar to--source-data, except that it is used to dump a replica server to produce a dump file that can be used to set up another server as a replica that has the same source as the dumped server. The option causes the dump output to include aCHANGE REPLICATION SOURCE TOstatement that indicates the binary log coordinates (file name and position) of the dumped replica's source. TheCHANGE REPLICATION SOURCE TOstatement reads the values ofRelay_Master_Log_FileandExec_Master_Log_Posfrom theSHOW REPLICA STATUSoutput and uses them forSOURCE_LOG_FILEandSOURCE_LOG_POSrespectively. These are the replication source server coordinates from which the replica starts replicating.Note已执行的中继日志中的事务顺序不一致可能会导致使用错误的位置。有关详细信息,请参阅第 19.5.1.34 节“复制和事务不一致”。Inconsistencies in the sequence of transactions from the relay log which have been executed can cause the wrong position to be used. See Section 19.5.1.34, “Replication and Transaction Inconsistencies” for more information.
--dump-replica会导致使用源坐标而不是转储服务器的坐标,如下所示由--source-data选项完成。此外,指定此选项会覆盖--source-data选项。--dump-replicacauses the coordinates from the source to be used rather than those of the dumped server, as is done by the--source-dataoption. In addition, specifying this option overrides the--source-dataoption.Warning--dump-replica如果要应用转储的服务器使用gtid_mode=ON和SOURCE_AUTO_POSITION=1。--dump-replicashould not be used if the server where the dump is going to be applied usesgtid_mode=ONandSOURCE_AUTO_POSITION=1.选项值的处理方式与
--source-data相同。设置不值或设置 1 会导致CHANGE REPLICATION SOURCE TO语句写入转储。设置 2 会导致语句被写入但包含在 SQL 注释中。在启用或禁用其他选项以及如何处理锁定方面,它与--source-data具有相同的效果。The option value is handled the same way as for--source-data. Setting no value or 1 causes aCHANGE REPLICATION SOURCE TOstatement to be written to the dump. Setting 2 causes the statement to be written but encased in SQL comments. It has the same effect as--source-datain terms of enabling or disabling other options and in how locking is handled.--dump-replica导致 mysqldump 停止复制转储之前的 SQL 线程,然后重新启动它。--dump-replicacauses mysqldump to stop the replication SQL thread before the dump and restart it again after.--dump-replica向服务器发送一个SHOW REPLICA STATUS语句来获取信息,因此它们需要足够的权限来执行该语句--dump-replicasends aSHOW REPLICA STATUSstatement to the server to obtain information, so they require privileges sufficient to execute that statement.--apply-replica-statements和--include-source-host-port选项可以与--dump-replica.--apply-replica-statementsand--include-source-host-portoptions can be used in conjunction with--dump-replica.--dump-slave[=value]--dump-slave[=value]命令行格式Command-Line Format --dump-slave[=value]已弃用Deprecated 是Yes 类型Type 数字Numeric 默认值Default Value 1有效值Valid Values 12这是
--dump-replica的已弃用别名。This is a deprecated alias for--dump-replica.命令行格式Command-Line Format --include-source-host-port类型Type 布尔Boolean 默认值Default Value FALSE添加主机名和 TCP/IP 端口号的
SOURCE_HOST和SOURCE_PORT选项副本源的CHANGE REPLICATION SOURCE TO语句位于使用--dump-replica选项。Adds theSOURCE_HOSTandSOURCE_PORToptions for the host name and TCP/IP port number of the replica's source, to theCHANGE REPLICATION SOURCE TOstatement in a replica dump produced with the--dump-replicaoption.命令行格式Command-Line Format --include-master-host-port已弃用Deprecated 是Yes 类型Type 布尔Boolean 默认值Default Value FALSE这是
--include-source-host-port的已弃用别名。This is a deprecated alias for--include-source-host-port.--master-data[=value]--master-data[=value]命令行格式Command-Line Format --master-data[=value]--master-data[=value]已弃用Deprecated 是Yes 类型Type 数字Numeric 默认值Default Value 1有效值Valid Values 12这是
--source-data.This is a deprecated alias for--source-data.--output-as-version=value--output-as-version=value命令行格式Command-Line Format --output-as-version=value--output-as-version=value类型Type 枚举Enumeration 默认值Default Value SERVERSERVER有效值Valid Values BEFORE_8_0_23BEFORE_8_2_0BEFORE_8_2_0确定与副本和事件相关的语句所使用的术语级别,从而可以创建与不接受新术语的旧版本 MySQL 兼容的转储。此选项可以采用以下任一值,其效果如下所列:Determines the level of terminology used for statements relating to replicas and events, making it possible to create dumps compatible with older versions of MySQL that do not accept the newer terminology. This option can take any one of the following values, with effects described as listed here:
SERVER:读取服务器版本并使用与该版本兼容的最新版本的语句。这是默认值。SERVER: Reads the server version and uses the latest versions of statements compatible with that version. This is the default value.BEFORE_8_0_23:使用已弃用术语(例如 “slave” 和 “master”)的复制 SQL 语句将写入输出,以代替使用 “副本”和“源”,如 8.0.23 之前的 MySQL 版本中一样。BEFORE_8_0_23: Replication SQL statements using deprecated terms such as “slave” and “master” are written to the output in place of those using “replica” and “source”, as in MySQL versions prior to 8.0.23.此选项还复制
BEFORE_8_2_0对SHOW CREATE EVENT。This option also duplicates the effects ofBEFORE_8_2_0on the output ofSHOW CREATE EVENT.BEFORE_8_2_0:此选项会导致SHOW CREATE EVENT以反映如何在版本 8.2.0 之前的 MySQL 服务器中创建事件,显示DISABLE ON SLAVE而不是DISABLE ON REPLICA。BEFORE_8_2_0: This option causesSHOW CREATE EVENTto reflect how the event would have been created in a MySQL server prior to version 8.2.0, displayingDISABLE ON SLAVErather thanDISABLE ON REPLICA.
此选项影响
--events,--dump-replica,--source-data,--apply-replica-statements和--include-source-host-port。This option affects the output from--events,--dump-replica,--source-data,--apply-replica-statements, and--include-source-host-port.--source-data[=value]--source-data[=value]命令行格式Command-Line Format --source-data[=value]--source-data[=value]类型Type 数字Numeric 默认值Default Value 1有效值Valid Values 12用于转储复制源服务器以生成转储文件,该文件可用于将另一台服务器设置为复制源服务器的副本来源。这些选项导致转储输出包含
CHANGE REPLICATION SOURCE TO语句,该语句指示转储服务器的二进制日志坐标(文件名和位置)。这些是复制源服务器坐标,在将转储文件加载到副本中后,副本应从该坐标开始复制。Used to dump a replication source server to produce a dump file that can be used to set up another server as a replica of the source. The options cause the dump output to include aCHANGE REPLICATION SOURCE TOstatement that indicates the binary log coordinates (file name and position) of the dumped server. These are the replication source server coordinates from which the replica should start replicating after you load the dump file into the replica.如果选项值为 2,则
CHANGE REPLICATION SOURCE TO语句将被写入 SQL 注释,因此仅供参考;重新加载转储文件时它不起作用。如果该选项值为 1,则该语句不会作为注释写入,并在重新加载转储文件时生效。如果未指定选项值,则默认值为 1。If the option value is 2, theCHANGE REPLICATION SOURCE TOstatement 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.--source-data向服务器发送SHOW BINARY LOG STATUS语句来获取信息,因此它们需要足够的权限才能执行那个声明。此选项还需要RELOAD权限,并且必须启用二进制日志。--source-datasends aSHOW BINARY LOG STATUSstatement to the server to obtain information, so they require privileges sufficient to execute that statement. This option also requires theRELOADprivilege and the binary log must be enabled.--source-data自动关闭--lock-tables。它们还会打开--lock-all-tables,除非还指定了--single-transaction,在这种情况下,仅在短时间内获取全局读锁转储的开始(请参阅--single-transaction的说明)。在所有情况下,对日志的任何操作都会在转储的确切时刻发生。--source-dataautomatically turns off--lock-tables. They also turn on--lock-all-tables, unless--single-transactionalso 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.还可以通过使用
--dump-replica选项转储源的现有副本来设置副本,该选项会覆盖--source-data使其成为忽略。It is also possible to set up a replica by dumping an existing replica of the source, using the--dump-replicaoption, which overrides--source-datacausing it to be ignored.--set-gtid-purged=value--set-gtid-purged=value命令行格式Command-Line Format --set-gtid-purged=value--set-gtid-purged=value类型Type 枚举Enumeration 默认值Default Value AUTOAUTO有效值Valid Values OFFOFFONONAUTOAUTO此选项适用于使用基于 GTID 的复制 (
gtid_mode=ON) 的服务器。它控制在转储输出中包含SET @@GLOBAL.gtid_purged语句,该语句更新重新加载转储文件的服务器上gtid_purged的值,以添加从源服务器的gtid_executed系统变量。gtid_purged保存已在服务器上应用的所有事务的 GTID,但不存在于服务器上的任何二进制日志文件中。 mysqldump 因此会添加在源服务器上执行的事务的 GTID,以便目标服务器按应用记录这些事务,尽管目标服务器的二进制日志中没有这些事务。--set-gtid-purged还控制包含SET @@SESSION.sql_log_bin=0语句,该语句在重新加载转储文件时禁用二进制日志记录。此语句可防止在转储文件执行时生成新的 GTID 并将其分配给转储文件中的事务,以便使用事务的原始 GTID。This option is for servers that use GTID-based replication (gtid_mode=ON). It controls the inclusion of aSET @@GLOBAL.gtid_purgedstatement in the dump output, which updates the value ofgtid_purgedon a server where the dump file is reloaded, to add the GTID set from the source server'sgtid_executedsystem variable.gtid_purgedholds the GTIDs of all transactions that have been applied on the server, but do not exist on any binary log file on the server. mysqldump therefore adds the GTIDs for the transactions that were executed on the source server, so that the target server records these transactions as applied, although it does not have them in its binary logs.--set-gtid-purgedalso controls the inclusion of aSET @@SESSION.sql_log_bin=0statement, which disables binary logging while the dump file is being reloaded. This statement prevents new GTIDs from being generated and assigned to the transactions in the dump file as they are executed, so that the original GTIDs for the transactions are used.如果您未设置
--set-gtid-purged选项,则默认情况下,如果您支持的服务器上启用了 GTID,转储输出中将包含SET @@GLOBAL.gtid_purged语句并且gtid_executed系统变量的全局值中的 GTID 集不为空。如果服务器上启用了 GTID,则还包含SET @@SESSION.sql_log_bin=0语句。If you do not set the--set-gtid-purgedoption, the default is that aSET @@GLOBAL.gtid_purgedstatement is included in the dump output if GTIDs are enabled on the server you are backing up, and the set of GTIDs in the global value of thegtid_executedsystem variable is not empty. ASET @@SESSION.sql_log_bin=0statement is also included if GTIDs are enabled on the server.您可以将
gtid_purged的值替换为指定的 GTID 集,或者在语句中添加加号 (+) 以将指定的 GTID 集附加到gtid_purged已持有的 GTID 集。 mysqldump 记录的SET @@GLOBAL.gtid_purged语句在特定于版本的注释中包含一个加号 (+),这样 MySQL 将转储文件中设置的 GTID 添加到现有的gtid_purged值。You can either replace the value ofgtid_purgedwith a specified GTID set, or add a plus sign (+) to the statement to append a specified GTID set to the GTID set that is already held bygtid_purged. TheSET @@GLOBAL.gtid_purgedstatement recorded by mysqldump includes a plus sign (+) in a version-specific comment, such that MySQL adds the GTID set from the dump file to the existinggtid_purgedvalue.需要注意的是,
SET @@GLOBAL.gtid_purged语句的 mysqldump 包含的值包括gtid_executed在服务器上设置,甚至更改了数据库的受抑制部分或服务器上未包含在部分转储中的其他数据库。这可能意味着在重播转储文件的服务器上更新gtid_purged值后,存在与目标服务器上任何数据不相关的 GTID。如果不在目标服务器上重播任何进一步的转储文件,无关的 GTID 不会对服务器的未来操作造成任何问题,但它们会使复制拓扑中不同服务器上的 GTID 集进行比较或协调变得更加困难。如果您确实在目标服务器上重播包含相同 GTID 的进一步转储文件(例如,来自同一源服务器的另一个部分转储),则第二个转储文件中的任何SET @@GLOBAL.gtid_purged语句都会失败。在这种情况下,请在重播转储文件之前手动删除该语句,或者输出不包含该语句的转储文件。It is important to note that the value that is included by mysqldump for theSET @@GLOBAL.gtid_purgedstatement includes the GTIDs of all transactions in thegtid_executedset on the server, even those that changed suppressed parts of the database, or other databases on the server that were not included in a partial dump. This can mean that after thegtid_purgedvalue has been updated on the server where the dump file is replayed, GTIDs are present that do not relate to any data on the target server. If you do not replay any further dump files on the target server, the extraneous GTIDs do not cause any problems with the future operation of the server, but they make it harder to compare or reconcile GTID sets on different servers in the replication topology. If you do replay a further dump file on the target server that contains the same GTIDs (for example, another partial dump from the same origin server), anySET @@GLOBAL.gtid_purgedstatement in the second dump file fails. In this case, either remove the statement manually before replaying the dump file, or output the dump file without the statement.如果
SET @@GLOBAL.gtid_purged语句在目标服务器上没有所需的结果,您可以从输出中排除该语句,或者包含该语句但将其注释掉,以便它不会自动执行。您还可以包含该语句,但在转储文件中手动编辑它以获得所需的结果。If theSET @@GLOBAL.gtid_purgedstatement would not have the desired result on your target server, you can exclude the statement from the output, or include it but comment it out so that it is not actioned automatically. You can also include the statement but manually edit it in the dump file to achieve the desired result.--set-gtid-purged选项的可能值如下:The possible values for the--set-gtid-purgedoption are as follows:-
AUTOAUTO 默认值。如果您要备份的服务器上启用了 GTID,并且
gtid_executed不为空,则SET @@GLOBAL.gtid_purged将添加到输出中,其中包含从gtid_executed。如果启用 GTID,SET @@SESSION.sql_log_bin=0将添加到输出中。如果服务器上未启用 GTID,则语句不会添加到输出中。The default value. If GTIDs are enabled on the server you are backing up andgtid_executedis not empty,SET @@GLOBAL.gtid_purgedis added to the output, containing the GTID set fromgtid_executed. If GTIDs are enabled,SET @@SESSION.sql_log_bin=0is added to the output. If GTIDs are not enabled on the server, the statements are not added to the output.-
OFFOFF SET @@GLOBAL.gtid_purged不会添加到输出中,并且SET @@SESSION.sql_log_bin=0不会添加到输出中。对于未使用 GTID 的服务器,请使用此选项或AUTO。仅当您确定所需的 GTID 集已存在于目标服务器上的gtid_purged且不应更改,或者您打算手动识别和添加任何缺失的 GTID 时,才对正在使用 GTID 的服务器使用此选项。SET @@GLOBAL.gtid_purgedis not added to the output, andSET @@SESSION.sql_log_bin=0is not added to the output. For a server where GTIDs are not in use, use this option orAUTO. Only use this option for a server where GTIDs are in use if you are sure that the required GTID set is already present ingtid_purgedon the target server and should not be changed, or if you plan to identify and add any missing GTIDs manually.-
ONON 如果要备份的服务器上启用了 GTID,
SET @@GLOBAL.gtid_purged将添加到输出中(除非gtid_executed为空),并且SET @@SESSION.sql_log_bin=0添加到输出中。如果设置此选项但服务器上未启用 GTID,则会发生错误。对于正在使用 GTID 的服务器,请使用此选项或AUTO,除非您确定目标服务器不需要gtid_executed中的 GTID。If GTIDs are enabled on the server you are backing up,SET @@GLOBAL.gtid_purgedis added to the output (unlessgtid_executedis empty), andSET @@SESSION.sql_log_bin=0is added to the output. An error occurs if you set this option but GTIDs are not enabled on the server. For a server where GTIDs are in use, use this option orAUTO, unless you are sure that the GTIDs ingtid_executedare not needed on the target server.-
COMMENTEDCOMMENTED 如果您要备份的服务器上启用了 GTID,
SET @@GLOBAL.gtid_purged将添加到输出中(除非gtid_executed为空),但它会被注释掉。这意味着gtid_executed的值在输出中可用,但重新加载转储文件时不会自动执行任何操作。SET @@SESSION.sql_log_bin=0添加到输出中,并且未注释掉。通过COMMENTED,您可以手动或自动控制gtid_executed设置的使用。例如,如果您要将数据迁移到另一台已经具有不同活动数据库的服务器,您可能更愿意这样做。If GTIDs are enabled on the server you are backing up,SET @@GLOBAL.gtid_purgedis added to the output (unlessgtid_executedis empty), but it is commented out. This means that the value ofgtid_executedis available in the output, but no action is taken automatically when the dump file is reloaded.SET @@SESSION.sql_log_bin=0is added to the output, and it is not commented out. WithCOMMENTED, you can control the use of thegtid_executedset manually or through automation. For example, you might prefer to do this if you are migrating data to another server that already has different active databases.
-
格式选项Format Options
以下选项指定如何表示整个转储文件或转储文件中的某些类型的数据。它们还控制是否将某些可选信息写入转储文件。The following options specify how to represent the entire dump file or certain kinds of data in the dump file. They also control whether certain optional information is written to the dump file.
命令行格式Command-Line Format --compact产生更紧凑的输出。此选项启用
--skip-add-drop-table、--skip-add-locks、--skip-comments、--skip-disable-keys和--skip-set-charset选项。Produce more compact output. This option enables the--skip-add-drop-table,--skip-add-locks,--skip-comments,--skip-disable-keys, and--skip-set-charsetoptions.--compatible=name--compatible=name命令行格式Command-Line Format --compatible=name[,name,...]--compatible=name[,name,...]类型Type 字符串String 默认值Default Value ''有效值Valid Values ansi生成与其他数据库系统或较旧的 MySQL 服务器更兼容的输出。该选项唯一允许的值为
ansi,它与设置服务器 SQL 模式的相应选项具有相同的含义。请参阅第 7.1.11 节“服务器 SQL 模式”。Produce output that is more compatible with other database systems or with older MySQL servers. The only permitted value for this option isansi, which has the same meaning as the corresponding option for setting the server SQL mode. See Section 7.1.11, “Server SQL Modes”.命令行格式Command-Line Format --complete-insert使用包含列名称的完整
INSERT语句。Use completeINSERTstatements that include column names.命令行格式Command-Line Format --create-options在
CREATE TABLE语句。Include all MySQL-specific table options in theCREATE TABLEstatements.--fields-terminated-by=...,--fields-enclosed-by=...,--fields-optionally-enclosed-by=...,--fields-escaped-by=...命令行格式Command-Line Format --fields-terminated-by=string--fields-terminated-by=string类型Type 字符串String 命令行格式Command-Line Format --fields-enclosed-by=string--fields-enclosed-by=string类型Type 字符串String 命令行格式Command-Line Format --fields-optionally-enclosed-by=string--fields-optionally-enclosed-by=string类型Type 字符串String 命令行格式Command-Line Format --fields-escaped-by类型Type 字符串String 这些选项与
--tab选项一起使用,含义与相应的FIELDS条款用于LOAD DATA。参见第 15.2.9 节,“LOAD DATA 语句”.These options are used with the--taboption and have the same meaning as the correspondingFIELDSclauses forLOAD DATA. See Section 15.2.9, “LOAD DATA Statement”.命令行格式Command-Line Format --hex-blob使用十六进制表示法转储二进制列(例如,
'abc'变为0x616263)。受影响的数据类型为BINARY、VARBINARY、BLOB类型、BIT、所有空间数据类型以及与binary字符集。Dump binary columns using hexadecimal notation (for example,'abc'becomes0x616263). The affected data types areBINARY,VARBINARY,BLOBtypes,BIT, all spatial data types, and other non-binary data types when used with thebinarycharacter set.该
--hex-blob当使用时,选项会被忽略--tab使用。The--hex-bloboption is ignored when the--tabis used.命令行格式Command-Line Format --lines-terminated-by=string--lines-terminated-by=string类型Type 字符串String 此选项与
--tab选项一起使用,其含义与相应的LINES条款用于LOAD DATA。参见第 15.2.9 节,“LOAD DATA 语句”.This option is used with the--taboption and has the same meaning as the correspondingLINESclause forLOAD DATA. See Section 15.2.9, “LOAD DATA Statement”.--quote-names,-Q命令行格式Command-Line Format --quote-names禁用者Disabled by skip-quote-names在
`字符内引用标识符(例如数据库、表和列名称)。如果启用ANSI_QUOTESSQL 模式,标识符会在"字符内加引号。此选项默认启用。可以使用--skip-quote-names禁用它,但应在任何选项(例如--compatible,可能会启用--quote-names。Quote identifiers (such as database, table, and column names) within`characters. If theANSI_QUOTESSQL 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--compatiblethat may enable--quote-names.--result-file=file_name,-r file_name--result-file=,file_name-rfile_name命令行格式Command-Line Format --result-file=file_name--result-file=file_name类型Type 文件名File name 直接输出到指定文件。即使在生成转储时发生错误,也会创建结果文件并覆盖其先前的内容。Direct output to the named file. The result file is created and its previous contents overwritten, even if an error occurs while generating the dump.
应在 Windows 上使用此选项,以防止换行
\n字符转换为\r\n回车/换行序列。This option should be used on Windows to prevent newline\ncharacters from being converted to\r\ncarriage return/newline sequences.--show-create-skip-secondary-engine=value--show-create-skip-secondary-engine=value命令行格式Command-Line Format --show-create-skip-secondary-engine从
SECONDARY ENGINE语句中排除CREATE TABLE条款。它通过在转储操作期间启用show_create_table_skip_secondary_engine系统变量来实现。此外,您可以在使用之前启用show_create_table_skip_secondary_engine系统变量mysqldump.Excludes theSECONDARY ENGINEclause fromCREATE TABLEstatements. It does so by enabling theshow_create_table_skip_secondary_enginesystem variable for the duration of the dump operation. Alternatively, you can enable theshow_create_table_skip_secondary_enginesystem variable prior to using mysqldump.--tab=dir_name,-T dir_name--tab=,dir_name-Tdir_name命令行格式Command-Line Format --tab=dir_name--tab=dir_name类型Type 目录名称Directory name 生成制表符分隔的文本格式数据文件。对于每个转储的表,mysqldump 创建一个
文件,其中包含tbl_name.sqlCREATE TABLE语句用于创建表,服务器写入包含其数据的文件。选项值是写入文件的目录。Produce tab-separated text-format data files. For each dumped table, mysqldump creates atbl_name.txtfile that contains thetbl_name.sqlCREATE TABLEstatement that creates the table, and the server writes afile that contains its data. The option value is the directory in which to write the files.tbl_name.txtNote仅当 mysqldump 与 mysqld 服务器。由于服务器会在您指定的目录中创建
*.txt文件,因此该目录必须可由服务器写入,并且您使用的 MySQL 帐户必须具有FILE权限。由于 mysqldump 在同一目录中创建*.sql,因此您的系统登录帐户必须可写入它。This option should be used only when mysqldump is run on the same machine as the mysqld server. Because the server creates*.txtfiles in the directory that you specify, the directory must be writable by the server and the MySQL account that you use must have theFILEprivilege. Because mysqldump creates*.sqlin the same directory, it must be writable by your system login account.默认情况下,
.txt数据文件的格式在列之间使用制表符值和每行末尾的换行符。可以使用--fields-和xxx--lines-terminated-by选项显式指定格式。By default, the.txtdata files are formatted using tab characters between column values and a newline at the end of each line. The format can be specified explicitly using the--fields-andxxx--lines-terminated-byoptions.列值将转换为
--default-character-set选项。Column values are converted to the character set specified by the--default-character-setoption.命令行格式Command-Line Format --tz-utc禁用者Disabled by skip-tz-utc此选项允许在不同时区的服务器之间转储和重新加载
TIMESTAMP列。 mysqldump 将其连接时区设置为 UTC 并将SET TIME_ZONE='+00:00'添加到转储文件中。如果没有此选项,TIMESTAMP列将在源服务器和目标服务器本地的时区中转储和重新加载,如果服务器位于不同的时区,这可能会导致值发生更改。--tz-utc还可以防止夏令时导致的更改。默认情况下启用--tz-utc。要禁用它,请使用--skip-tz-utc。This option enablesTIMESTAMPcolumns to be dumped and reloaded between servers in different time zones. mysqldump sets its connection time zone to UTC and addsSET TIME_ZONE='+00:00'to the dump file. Without this option,TIMESTAMPcolumns are dumped and reloaded in the time zones local to the source and destination servers, which can cause the values to change if the servers are in different time zones.--tz-utcalso protects against changes due to daylight saving time.--tz-utcis enabled by default. To disable it, use--skip-tz-utc.--xml,-X命令行格式Command-Line Format --xml将转储输出写入格式正确的 XML。Write dump output as well-formed XML.
NULL、'NULL'和空值:对于名为column_name的列,NULL值、空字符串和字符串值'NULL'为在此选项生成的输出中相互区分如下。NULL,'NULL', and Empty Values: For a column namedcolumn_name, theNULLvalue, an empty string, and the string value'NULL'are distinguished from one another in the output generated by this option as follows.值:Value: XML 表示形式:XML Representation: NULL(未知值)NULL(unknown value)<field name="column_name" xsi:nil="true" />''(空字符串)''(empty string)<field name="column_name"></field>'NULL'(字符串值)'NULL'(string value)<field name="column_name">NULL</field>从mysql客户端运行时的输出
--xml选项也遵循前述规则。(见第 6.5.1.1 节,“mysql 客户端选项”.)The output from the mysql client when run using the--xmloption also follows the preceding rules. (See Section 6.5.1.1, “mysql Client Options”.)mysqldump 包括 XML 命名空间,如下所示:XML output from mysqldump includes the XML namespace, as shown here:
$>
mysqldump --xml -u root world City<?xml version="1.0"?> <mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <database name="world"> <table_structure name="City"> <field Field="ID" Type="int(11)" Null="NO" Key="PRI" Extra="auto_increment" /> <field Field="Name" Type="char(35)" Null="NO" Key="" Default="" Extra="" /> <field Field="CountryCode" Type="char(3)" Null="NO" Key="" Default="" Extra="" /> <field Field="District" Type="char(20)" Null="NO" Key="" Default="" Extra="" /> <field Field="Population" Type="int(11)" Null="NO" Key="" Default="0" Extra="" /> <key Table="City" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="ID" Collation="A" Cardinality="4079" Null="" Index_type="BTREE" Comment="" /> <options Name="City" Engine="MyISAM" Version="10" Row_format="Fixed" Rows="4079" Avg_row_length="67" Data_length="273293" Max_data_length="18858823439613951" Index_length="43008" Data_free="0" Auto_increment="4080" Create_time="2007-03-31 01:47:01" Update_time="2007-03-31 01:47:02" Collation="latin1_swedish_ci" Create_options="" Comment="" /> </table_structure> <table_data name="City"> <row> <field name="ID">1</field> <field name="Name">Kabul</field> <field name="CountryCode">AFG</field> <field name="District">Kabol</field> <field name="Population">1780000</field> </row>...<row> <field name="ID">4079</field> <field name="Name">Rafah</field> <field name="CountryCode">PSE</field> <field name="District">Rafah</field> <field name="Population">92020</field> </row> </table_data> </database> </mysqldump>
过滤选项Filtering Options
以下选项控制将哪种类型的架构对象写入转储文件: 按类别,例如触发器或事件;按名称,例如,选择要转储的数据库和表;甚至使用 WHERE 子句过滤表数据中的行。The following options control which kinds of schema objects are
written to the dump file: by category, such as triggers or
events; by name, for example, choosing which databases and
tables to dump; or even filtering rows from the table data using
a WHERE clause.
--all-databases,-A命令行格式Command-Line Format --all-databases转储所有表中的所有表数据库。这与使用
--databases选项并在命令行上命名所有数据库相同。Dump all tables in all databases. This is the same as using the--databasesoption and naming all the databases on the command line.Note请参阅
--add-drop-database描述,以了解该选项与--all-databases.See the--add-drop-databasedescription for information about an incompatibility of that option with--all-databases.Prior to MySQL 8.4, the
--routines以及--events选项进行更改。mysqldump were not required to include stored routines and events when using the--all-databasesoption: The dump included themysqlsystem database, and therefore also themysql.proc以及mysql.eventtables containing stored routine and event definitions. As of MySQL 8.4, themysql.event以及mysql.proctables are not used. Definitions for the corresponding objects are stored in data dictionary tables, but those tables are not dumped. To include stored routines and events in a dump made using--all-databases, use the--routines以及--eventsoptions explicitly.Prior to MySQL 8.4, the--routinesand--eventsoptions for mysqldump were not required to include stored routines and events when using the--all-databasesoption: The dump included themysqlsystem database, and therefore also themysql.procandmysql.eventtables containing stored routine and event definitions. As of MySQL 8.4, themysql.eventandmysql.proctables are not used. Definitions for the corresponding objects are stored in data dictionary tables, but those tables are not dumped. To include stored routines and events in a dump made using--all-databases, use the--routinesand--eventsoptions explicitly.--databases,-B命令行格式Command-Line Format --databases--databases转储多个数据库。通常,mysqldump 将命令行上的第一个名称参数视为数据库名称,将后面的名称视为表名称。使用此选项,它将所有名称参数视为数据库名称。
CREATE DATABASE和USE语句包含在每个新数据库之前的输出中。Dump several databases. Normally, mysqldump treats the first name argument on the command line as a database name and following names as table names. With this option, it treats all name arguments as database names.CREATE DATABASEandUSEstatements are included in the output before each new database.此选项可用于转储
performance_schema数据库,即使使用--all-databases选项,通常也不会转储该数据库。 (还可以使用--skip-lock-tables选项。)This option may be used to dump theperformance_schemadatabase, which normally is not dumped even with the--all-databasesoption. (Also use the--skip-lock-tablesoption.)Note有关该选项不兼容的信息,请参阅
--add-drop-database说明与--databases。See the--add-drop-databasedescription for information about an incompatibility of that option with--databases.--events,-E命令行格式Command-Line Format --events在输出中包含转储数据库的事件计划程序事件。此选项需要这些数据库的
EVENT权限。Include Event Scheduler events for the dumped databases in the output. This option requires theEVENTprivileges for those databases.使用
--events生成的输出包含CREATE EVENT语句来创建事件。The output generated by using--eventscontainsCREATE EVENTstatements to create the events.--ignore-error=error[,error]...--ignore-error=error[,error]...命令行格式Command-Line Format --ignore-error=error[,error]...--ignore-error=error[,error]...类型Type 字符串String 忽略指定的错误。该选项值是逗号分隔的错误号列表,指定在 mysqldump 执行期间要忽略的错误。如果还指定了
--force选项来忽略所有错误,则--force优先。Ignore the specified errors. The option value is a list of comma-separated error numbers specifying the errors to ignore during mysqldump execution. If the--forceoption is also given to ignore all errors,--forcetakes precedence.--ignore-table=db_name.tbl_name--ignore-table=db_name.tbl_name命令行格式Command-Line Format --ignore-table=db_name.tbl_name类型Type 字符串String 不要转储给定的表,该表必须使用数据库名称和表名称指定。要忽略多个表,请多次使用此选项。此选项还可用于忽略视图。Do not dump the given table, which must be specified using both the database and table names. To ignore multiple tables, use this option multiple times. This option also can be used to ignore views.
--ignore-views=boolean--ignore-views=boolean命令行格式Command-Line Format --ignore-views类型Type 布尔Boolean 默认值Default Value FALSE跳过转储文件中的表视图。Skips table views in the dump file.
命令行格式Command-Line Format --init-command=str类型Type 字符串String 连接到 MySQL 服务器后执行的单个 SQL 语句。该定义会重置由它或
init-command-add定义的现有语句。Single SQL statement to execute after connecting to the MySQL server. The definition resets existing statements defined by it orinit-command-add.命令行格式Command-Line Format --init-command-add=str类型Type 字符串String 添加一条额外的 SQL 语句,以便在连接或重新连接到 MySQL 服务器后执行。它可以在没有
--init-command的情况下使用,但如果在它之前使用则无效,因为init-command会重置要调用的命令列表。Add an additional SQL statement to execute after connecting or reconnecting to the MySQL server. It's usable without--init-commandbut has no effect if used before it becauseinit-commandresets the list of commands to call.--no-data,-d命令行格式Command-Line Format --no-data不写入任何表行信息(即不转储表内容)。如果您只想转储表的
CREATE TABLE语句(例如,通过加载转储文件创建表的空副本),这非常有用。Do not write any table row information (that is, do not dump table contents). This is useful if you want to dump only theCREATE TABLEstatement for the table (for example, to create an empty copy of the table by loading the dump file).--routines,-R命令行格式Command-Line Format --routines在输出中包含转储数据库的存储例程(过程和函数)。此选项需要全局
SELECT权限。Include stored routines (procedures and functions) for the dumped databases in the output. This option requires the globalSELECTprivilege.使用
--routines生成的输出包含CREATE PROCEDURE和CREATE FUNCTION语句来创建例程。The output generated by using--routinescontainsCREATE PROCEDUREandCREATE FUNCTIONstatements to create the routines.--skip-generated-invisible-primary-key命令行格式Command-Line Format --skip-generated-invisible-primary-key类型Type 布尔Boolean 默认值Default Value FALSE此选项会导致生成的不可见主键从输出中排除。有关详细信息,请参阅第 15.1.20.11 节“生成的不可见主键”。This option causes generated invisible primary keys to be excluded from the output. For more information, see Section 15.1.20.11, “Generated Invisible Primary Keys”.
命令行格式Command-Line Format --tables覆盖
--databases或-B选项。 mysqldump 将选项后面的所有名称参数视为表名称。Override the--databasesor-Boption. mysqldump regards all name arguments following the option as table names.命令行格式Command-Line Format --triggers禁用者Disabled by skip-triggers在输出中包含每个转储表的触发器。该选项默认启用;使用
--skip-triggers禁用它。Include triggers for each dumped table in the output. This option is enabled by default; disable it with--skip-triggers.要能够转储表的触发器,您必须拥有该表的
TRIGGER权限。To be able to dump a table's triggers, you must have theTRIGGERprivilege for the table.允许使用多个触发器。 mysqldump 按激活顺序转储触发器,以便在重新加载转储文件时,按相同的激活顺序创建触发器。但是,如果 mysqldump 转储文件包含具有相同触发事件和操作时间的表的多个触发器,则尝试将转储文件加载到不支持多个触发器的旧服务器时会发生错误。 (有关解决方法,请参阅降级说明;您可以转换触发器以与旧服务器兼容。)Multiple triggers are permitted. mysqldump dumps triggers in activation order so that when the dump file is reloaded, triggers are created in the same activation order. However, if a mysqldump dump file contains multiple triggers for a table that have the same trigger event and action time, an error occurs for attempts to load the dump file into an older server that does not support multiple triggers. (For a workaround, see Downgrade Notes; you can convert triggers to be compatible with older servers.)
--where=',where_condition'-w 'where_condition'命令行格式Command-Line Format --where='where_condition'仅转储由给定
WHERE条件选择的行。如果条件包含空格或命令解释器特有的其他字符,则必须在条件周围加引号。Dump only rows selected by the givenWHEREcondition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.示例:Examples:
--where="user='jimf'" -w"userid>1" -w"userid<1"
性能选项Performance Options
The following options are the most relevant for the performance
particularly of the restore operations. For large data sets,
restore operation (processing the INSERT
statements in the dump file) is the most time-consuming part.
When it is urgent to restore data quickly, plan and test the
performance of this stage in advance. For restore times measured
in hours, you might prefer an alternative backup and restore
solution, such as
MySQL Enterprise 备份 for
InnoDB-only and mixed-use databases.The following options are the most relevant for the performance
particularly of the restore operations. For large data sets,
restore operation (processing the INSERT
statements in the dump file) is the most time-consuming part.
When it is urgent to restore data quickly, plan and test the
performance of this stage in advance. For restore times measured
in hours, you might prefer an alternative backup and restore
solution, such as
MySQL Enterprise Backup for
InnoDB-only and mixed-use databases.
性能还受到事务选项,主要用于转储操作。Performance is also affected by the transactional options, primarily for the dump operation.
命令行格式Command-Line Format --column-statistics类型Type 布尔Boolean 默认值Default Value OFFOFF将
ANALYZE TABLE语句添加到输出中,以便在重新加载转储文件时生成转储表的直方图统计信息。默认情况下禁用此选项,因为大型表的直方图生成可能需要很长时间。AddANALYZE TABLEstatements to the output to generate histogram statistics for dumped tables when the dump file is reloaded. This option is disabled by default because histogram generation for large tables can take a long time.--disable-keys,-K命令行格式Command-Line Format --disable-keys对于每个表,将
INSERT语句用/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;和/*!40000 ALTER TABLE tbl_name ENABLE KEYS */;语句。这使得加载转储文件更快,因为索引是在插入所有行之后创建的。此选项仅对MyISAM表的非唯一索引有效。For each table, surround theINSERTstatements with/*!40000 ALTER TABLEandtbl_nameDISABLE KEYS */;/*!40000 ALTER TABLEstatements. This makes loading the dump file faster because the indexes are created after all rows are inserted. This option is effective only for nonunique indexes oftbl_nameENABLE KEYS */;MyISAMtables.命令行格式Command-Line Format --extended-insert禁用者Disabled by skip-extended-insert使用包含多个
VALUES列表的多行语法编写INSERT语句。这会导致转储文件更小,并加快文件重新加载时的插入速度。WriteINSERTstatements using multiple-row syntax that includes severalVALUESlists. This results in a smaller dump file and speeds up inserts when the file is reloaded.命令行格式Command-Line Format --insert-ignore编写
INSERT IGNORE语句,而不是INSERT语句。WriteINSERT IGNOREstatements rather thanINSERTstatements.--max-allowed-packet=value--max-allowed-packet=value命令行格式Command-Line Format --max-allowed-packet=value--max-allowed-packet=value类型Type 数字Numeric 默认值Default Value 25165824客户端/服务器通信缓冲区的最大大小。默认为 24MB,最大为 1GB。The maximum size of the buffer for client/server communication. The default is 24MB, the maximum is 1GB.
Note此选项的值特定于 mysqldump,不应与 MySQL 服务器的
max_allowed_packet系统变量;无论 mysqldump 的单个数据包不能超过服务器值,无论 mysqldump 选项,即使后者较大。The value of this option is specific to mysqldump and should not be confused with the MySQL server'smax_allowed_packetsystem variable; the server value cannot be exceeded by a single packet from mysqldump, regardless of any setting for the mysqldump option, even if the latter is larger.--mysqld-long-query-time=value--mysqld-long-query-time=value命令行格式Command-Line Format --mysqld-long-query-time=value--mysqld-long-query-time=value类型Type 数字Numeric 默认值Default Value Server global settingServer global setting设置
long_query_time系统变量。如果您想增加 mysqldump 查询在记录到慢速查询日志文件之前所允许的时间,请使用此选项。 mysqldump 执行全表扫描,这意味着其查询通常会超出有用的全局long_query_time设置用于常规查询。默认全局设置为 10 秒。Set the session value of thelong_query_timesystem variable. Use this option if you want to increase the time allowed for queries from mysqldump before they are logged to the slow query log file. mysqldump performs a full table scan, which means its queries can often exceed a globallong_query_timesetting that is useful for regular queries. The default global setting is 10 seconds.您可以使用
--mysqld-long-query-time指定从 0 开始的会话值(这意味着来自 mysqldump 记录到慢查询日志)为 31536000,即 365 天(以秒为单位)。对于 mysqldump 的选项,您只能指定整秒。如果不指定此选项,服务器的全局设置将应用于mysqldump 的查询。You can use--mysqld-long-query-timeto specify a session value from 0 (meaning that every query from mysqldump is logged to the slow query log) to 31536000, which is 365 days in seconds. For mysqldump’s option, you can only specify whole seconds. When you do not specify this option, the server’s global setting applies to mysqldump’s queries.--net-buffer-length=value--net-buffer-length=value命令行格式Command-Line Format --net-buffer-length=value类型Type 数字Numeric 默认值Default Value 16384客户端/服务器通信缓冲区的初始大小。创建多行
INSERT语句时(与--extended-insert或--opt选项),mysqldump 创建最多--net-buffer-length字节长。如果增加此变量,请确保 MySQL 服务器net_buffer_length系统变量的值至少有这么大。The initial size of the buffer for client/server communication. When creating multiple-rowINSERTstatements (as with the--extended-insertor--optoption), mysqldump creates rows up to--net-buffer-lengthbytes long. If you increase this variable, ensure that the MySQL servernet_buffer_lengthsystem variable has a value at least this large.命令行格式Command-Line Format --network-timeout[={0|1}]类型Type 布尔Boolean 默认值Default Value TRUE通过设置
--max-allowed-packet为其最大值,网络读写超时为较大值。默认情况下启用此选项。要禁用它,请使用--skip-network-timeout。Enable large tables to be dumped by setting--max-allowed-packetto its maximum value and network read and write timeouts to a large value. This option is enabled by default. To disable it, use--skip-network-timeout.命令行格式Command-Line Format --opt禁用者Disabled by skip-opt此选项默认启用,是
--add-drop-table--add-locks--create-options--disable-keys--extended-insert--lock-tables--quick--set-charset。它提供快速转储操作并生成可以快速重新加载到 MySQL 服务器的转储文件。This option, enabled by default, is shorthand for the combination of--add-drop-table--add-locks--create-options--disable-keys--extended-insert--lock-tables--quick--set-charset. It gives a fast dump operation and produces a dump file that can be reloaded into a MySQL server quickly.由于
--opt选项默认启用,因此您只需指定其相反的--skip-opt即可关闭多个默认设置。有关选择性启用或禁用受--opt影响的选项子集的信息,请参阅mysqldump选项组 的讨论。Because the--optoption is enabled by default, you only specify its converse, the--skip-optto turn off several default settings. See the discussion ofmysqldumpoption groups for information about selectively enabling or disabling a subset of the options affected by--opt.--quick,-q命令行格式Command-Line Format --quick--quick禁用者Disabled by skip-quick此选项对于转储大型表很有用。它强制 mysqldump 从服务器一次一行检索表中的行,而不是检索整个行集并在将其写出之前将其缓冲在内存中。This option is useful for dumping large tables. It forces mysqldump to retrieve rows for a table from the server a row at a time rather than retrieving the entire row set and buffering it in memory before writing it out.
命令行格式Command-Line Format --skip-opt
事务选项Transactional Options
以下选项会权衡转储操作的性能与导出数据的可靠性和一致性。The following options trade off the performance of the dump operation, against the reliability and consistency of the exported data.
命令行格式Command-Line Format --add-locks用
LOCK TABLES和UNLOCK TABLES语句。这会导致重新加载转储文件时插入速度更快。请参阅第 10.2.5.1 节“优化 INSERT 语句”。Surround each table dump withLOCK TABLESandUNLOCK TABLESstatements. This results in faster inserts when the dump file is reloaded. See Section 10.2.5.1, “Optimizing INSERT Statements”.--flush-logs,-F命令行格式Command-Line Format --flush-logs在开始转储之前刷新 MySQL 服务器日志文件。此选项需要
RELOAD权限。如果将此选项与--all-databases选项结合使用,则对于每个转储的数据库都会刷新日志。例外情况是使用--lock-all-tables、--source-data或--single-transaction。在这些情况下,日志仅刷新一次,对应于所有表被FLUSH TABLES WITH READ LOCK锁定的时刻。如果您希望转储和日志刷新在完全相同的时刻发生,则应将--flush-logs与--lock-all-tables、--source-data,或--single-transaction。Flush the MySQL server log files before starting the dump. This option requires theRELOADprivilege. If you use this option in combination with the--all-databasesoption, the logs are flushed for each database dumped. The exception is when using--lock-all-tables,--source-data, or--single-transaction. In these cases, the logs are flushed only once, corresponding to the moment that all tables are locked byFLUSH TABLES WITH READ LOCK. If you want your dump and the log flush to happen at exactly the same moment, you should use--flush-logstogether with--lock-all-tables,--source-data, or--single-transaction.命令行格式Command-Line Format --flush-privileges转储
mysql数据库后,将FLUSH PRIVILEGES语句添加到转储输出中。每当转储包含mysql数据库以及依赖于mysql数据库中的数据才能正确恢复的任何其他数据库时,都应使用此选项。Add aFLUSH PRIVILEGESstatement to the dump output after dumping themysqldatabase. This option should be used any time the dump contains themysqldatabase and any other database that depends on the data in themysqldatabase for proper restoration.由于转储文件包含
FLUSH PRIVILEGES语句,因此重新加载文件需要足够的权限执行该语句。Because the dump file contains aFLUSH PRIVILEGESstatement, reloading the file requires privileges sufficient to execute that statement.命令行格式Command-Line Format --lock-all-tables锁定所有数据库中的所有表。这是通过在整个转储期间获取全局读锁来实现的。此选项会自动关闭
--single-transaction和--lock-tables。Lock all tables across all databases. This is achieved by acquiring a global read lock for the duration of the whole dump. This option automatically turns off--single-transactionand--lock-tables.--lock-tables,-l命令行格式Command-Line Format --lock-tables对于每个转储的数据库,在转储之前锁定所有要转储的表。这些表使用
READ LOCAL锁定,以允许在MyISAM表的情况下进行并发插入。对于诸如InnoDB之类的事务表,--single-transaction是比--lock-tables更好的选择,因为它根本不需要锁定表。For each dumped database, lock all tables to be dumped before dumping them. The tables are locked withREAD LOCALto permit concurrent inserts in the case ofMyISAMtables. For transactional tables such asInnoDB,--single-transactionis a much better option than--lock-tablesbecause it does not need to lock the tables at all.因为
--lock-tables分别锁定每个数据库的表,此选项不保证转储文件中的表在数据库之间逻辑一致。不同数据库中的表可能会以完全不同的状态转储。Because--lock-tableslocks tables for each database separately, this option does not guarantee that the tables in the dump file are logically consistent between databases. Tables in different databases may be dumped in completely different states.某些选项,例如
--opt,会自动启用--lock-tables。如果要覆盖此设置,请在选项列表末尾使用--skip-lock-tables。Some options, such as--opt, automatically enable--lock-tables. If you want to override this, use--skip-lock-tablesat the end of the option list.命令行格式Command-Line Format --no-autocommit--no-autocommit将每个转储表的
INSERT语句括在SET autocommit = 0和COMMIT语句。Enclose theINSERTstatements for each dumped table withinSET autocommit = 0andCOMMITstatements.命令行格式Command-Line Format --order-by-primary每张表的行按其主键排序,或者如果存在,则按其第一个唯一索引排序。将表
MyISAM导出以便加载到InnoDB表时,这非常有用,但会显著增加导出操作所需时间。Dump each table's rows sorted by its primary key, or by its first unique index, if such an index exists. This is useful when dumping aMyISAMtable to be loaded into anInnoDBtable, but makes the dump operation take considerably longer.--shared-memory-base-name=name--shared-memory-base-name=name命令行格式Command-Line Format --shared-memory-base-name=name--shared-memory-base-name=name特定平台Platform Specific 窗口Windows 在 Windows 上,通过共享内存连接到本地服务器时使用的共享内存名称。默认值是
MYSQL。共享内存名称区分大小写。On Windows, the shared-memory name to use for connections made using shared memory to a local server. The default value isMYSQL. The shared-memory name is case-sensitive.此选项仅在服务器启用了
shared_memory系统变量以支持共享内存连接时适用。This option applies only if the server was started with theshared_memorysystem variable enabled to support shared-memory connections.命令行格式Command-Line Format --single-transaction此选项将事务隔离模式设置为
REPEATABLE READ并发送START TRANSACTION在转储数据之前向服务器发送 SQL 语句。它仅对诸如InnoDB之类的事务表有用,因为这样它会在发出START TRANSACTION时转储数据库的一致状态,而不会阻塞任何应用程序。This option sets the transaction isolation mode toREPEATABLE READand sends aSTART TRANSACTIONSQL statement to the server before dumping data. It is useful only with transactional tables such asInnoDB, because then it dumps the consistent state of the database at the time whenSTART TRANSACTIONwas issued without blocking any applications.RELOAD或FLUSH_TABLES权限需要--single-transaction如果gtid_mode=ON和gtid_purged=ON|AUTO。TheRELOADorFLUSH_TABLESprivilege is required with--single-transactionif bothgtid_mode=ONandgtid_purged=ON|AUTO.使用此选项时,您应该记住,只有
InnoDB表会以一致状态转储。例如,使用此选项时转储的任何MyISAM或MEMORY表仍可能更改状态。When using this option, you should keep in mind that onlyInnoDBtables are dumped in a consistent state. For example, anyMyISAMorMEMORYtables dumped while using this option may still change state.在
--single-transaction导出过程中,为确保导出文件有效(表内容和二进制日志坐标正确),不应有其他连接使用以下语句:ALTER TABLE,CREATE TABLE,DROP TABLE,RENAME TABLE,TRUNCATE TABLE。一致性读并没有隔离这些语句,因此在要导出的表中使用它们可能会导致SELECT由mysqldump执行的表内容检索获取错误内容或失败。While a--single-transactiondump 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 theSELECTthat is performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail.--single-transaction选项和--lock-tables选项是互斥的,因为LOCK TABLES会导致隐式提交任何挂起的事务。The--single-transactionoption and the--lock-tablesoption are mutually exclusive becauseLOCK TABLEScauses any pending transactions to be committed implicitly.要转储大型表,请将
--single-transaction选项与--quick选项。To dump large tables, combine the--single-transactionoption with the--quickoption.
选项组Option Groups
--opt选项可打开多个设置,这些设置协同工作以执行快速转储操作。默认情况下,所有这些设置均处于启用状态,因为--opt默认情况下处于启用状态。因此,您很少指定--opt。相反,您可以通过指定--skip-opt来整体关闭这些设置,然后通过稍后在命令行上指定关联选项来选择性地重新启用某些设置。The--optoption turns on several settings that work together to perform a fast dump operation. All of these settings are on by default, because--optis on by default. Thus you rarely if ever specify--opt. Instead, you can turn these settings off as a group by specifying--skip-opt, then optionally re-enable certain settings by specifying the associated options later on the command line.--compact选项会关闭多个控制可选语句和注释是否出现在输出中的设置。同样,您可以在此选项后面加上其他选项来重新启用某些设置,或者使用--skip-compact表单打开所有设置。The--compactoption turns off several settings that control whether optional statements and comments appear in the output. Again, you can follow this option with other options that re-enable certain settings, or turn all the settings on by using the--skip-compactform.
当您有选择地启用或禁用组选项的效果时,顺序很重要,因为选项是从头到尾处理的。例如, --disable-keys --lock-tables --skip-opt 不会达到预期效果;它与 --skip-opt 本身相同。When you selectively enable or disable the effect of a group
option, order is important because options are processed first
to last. For example,
--disable-keys
--lock-tables
--skip-opt would not have the
intended effect; it is the same as
--skip-opt by itself.
示例Examples
要备份整个数据库:To make a backup of an entire database:
mysqldumpdb_name>backup-file.sql
要将转储文件加载回服务器:To load the dump file back into the server:
mysqldb_name<backup-file.sql
重新加载转储文件的另一种方法:Another way to reload the dump file:
mysql -e "source/path-to-backup/backup-file.sql"db_name
mysqldump 对于通过将数据从一台 MySQL 服务器复制到另一台 MySQL 服务器来填充数据库也非常有用:mysqldump is also very useful for populating databases by copying data from one MySQL server to another:
mysqldump --optdb_name| mysql --host=remote_host-Cdb_name
您可以使用一个命令转储多个数据库:You can dump several databases with one command:
mysqldump --databasesdb_name1[db_name2...] > my_databases.sql
要转储所有数据库,请使用 --all-databases 选项:To dump all databases, use the
--all-databases option:
mysqldump --all-databases > all_databases.sql
对于 InnoDB 表,mysqldump 提供了一种进行在线备份的方法:For InnoDB tables,
mysqldump provides a way of making an online
backup:
mysqldump --all-databases --source-data --single-transaction > all_databases.sql
此备份在转储开始时获取所有表的全局读锁(使用 FLUSH TABLES WITH READ LOCK)。一旦获得该锁,就会读取二进制日志坐标并释放该锁。如果在发出FLUSH语句时正在运行长更新语句,MySQL 服务器可能会停止,直到这些语句完成。之后,转储变得无锁,并且不会干扰表上的读写。如果 MySQL 服务器接收到的更新语句很短(就执行时间而言),则初始锁定期应该不会很明显,即使有很多更新。This backup acquires a global read lock on all tables (using
FLUSH TABLES WITH READ LOCK) at
the beginning of the dump. As soon as this lock has been
acquired, the binary log coordinates are read and the lock is
released. If long updating statements are running when the
FLUSH statement is issued, the
MySQL server may get stalled until those statements finish.
After that, the dump becomes lock free and does not disturb
reads and writes on the tables. If the update statements that
the MySQL server receives are short (in terms of execution
time), the initial lock period should not be noticeable, even
with many updates.
对于时间点恢复(也称为“前滚,”,当您需要恢复旧备份并重播自该备份以来发生的更改时),轮转二进制日志通常很有用(请参阅第 7.4.4 节“二进制日志”)或至少知道转储对应的二进制日志坐标:For point-in-time recovery (also known as “roll-forward,” when you need to restore an old backup and replay the changes that happened since that backup), it is often useful to rotate the binary log (see Section 7.4.4, “The Binary Log”) or at least know the binary log coordinates to which the dump corresponds:
mysqldump --all-databases --source-data=2 > all_databases.sql
或者:Or:
mysqldump --all-databases --flush-logs --source-data=2 > all_databases.sql
--source-data 选项可以与 --single-transaction 选项,如果使用 InnoDB 存储引擎存储表,该选项提供了一种方便的方法来进行在线备份,适合在时间点恢复之前使用。The --source-data option can
be used simultaneously with the
--single-transaction option,
which provides a convenient way to make an online backup
suitable for use prior to point-in-time recovery if tables are
stored using the InnoDB storage engine.
有关进行备份的详细信息,请参阅 第 9.2 节“数据库备份方法”,以及第 9.3 节“备份和恢复策略示例”。For more information on making backups, see Section 9.2, “Database Backup Methods”, and Section 9.3, “Example Backup and Recovery Strategy”.
要选择除某些功能之外的
--opt的效果,请对每个功能使用--skip选项。要禁用扩展插入和内存缓冲,请使用--opt--skip-extended-insert--skip-quick。 (实际上,--skip-extended-insert--skip-quick就足够了,因为--opt默认情况下处于启用状态。)To select the effect of--optexcept for some features, use the--skipoption for each feature. To disable extended inserts and memory buffering, use--opt--skip-extended-insert--skip-quick. (Actually,--skip-extended-insert--skip-quickis sufficient because--optis on by default.)要反转
--opt除禁用索引和表锁定之外的所有功能,请使用--skip-opt--disable-keys--lock-tables。To reverse--optfor all features except disabling of indexes and table locking, use--skip-opt--disable-keys--lock-tables.
限制Restrictions
mysqldump 默认情况下不会转储 performance_schema 或 sys 架构。要转储其中任何一个,请在命令行上明确命名它们。您还可以使用 --databases 选项命名它们。对于 performance_schema,还可以使用 --skip-lock-tables 选项。mysqldump does not dump the
performance_schema or sys
schema by default. To dump any of these, name them explicitly on
the command line. You can also name them with the
--databases option. For
performance_schema, also use the
--skip-lock-tables
option.
mysqldump 不会转储 INFORMATION_SCHEMA 架构。mysqldump does not dump the
INFORMATION_SCHEMA schema.
mysqldump 不会转储 InnoDB CREATE
TABLESPACE 语句。mysqldump does not dump
InnoDB CREATE
TABLESPACE statements.
mysqldump 不会转储 NDB Cluster ndbinfo 信息数据库。mysqldump does not dump the NDB Cluster
ndbinfo information database.
mysqldump 包含用于重新创建 general_log 和 slow_query_log 表以转储 mysql 数据库的语句。日志表内容不会转储。mysqldump includes statements to recreate the
general_log and
slow_query_log tables for dumps of the
mysql database. Log table contents are not
dumped.
如果由于权限不足而在备份视图时遇到问题,请参阅第 27.9 节“视图限制”了解解决方法。If you encounter problems backing up views due to insufficient privileges, see Section 27.9, “Restrictions on Views” for a workaround.