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. mysqldump客户端实用程序执行逻辑备份,生成一组SQL语句,可以执行这些语句来再现原始数据库对象定义和表数据。It dumps one or more MySQL databases for backup or transfer to another SQL server. 它转储一个或多个MySQL数据库以进行备份或传输到另一个SQL服务器。The mysqldump command can also generate output in CSV, other delimited text, or XML format.mysqldump命令还可以生成CSV、其他分隔文本或XML格式的输出。
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 Database Service compatibility checks and modifications. 考虑使用MySQL Shell转储实用程序,该实用程序提供多线程并行转储、文件压缩和进度信息显示,以及Oracle云基础设施对象存储流和MySQL数据库服务兼容性检查和修改等云功能。Dumps can be easily imported into a MySQL Server instance or a MySQL Database Service DB System using the MySQL Shell load dump utilities. 转储可以使用MySQL Shell加载转储实用程序轻松导入MySQL Server实例或MySQL数据库服务DB系统。Installation instructions for MySQL Shell can be found here.MySQL Shell的安装说明可以在这里找到。
mysqldump requires at least the mysqldump至少要求转储表具有SELECT
privilege for dumped tables, SHOW VIEW
for dumped views, TRIGGER
for dumped triggers, LOCK TABLES
if the --single-transaction
option is not used, and (as of MySQL 8.0.21) PROCESS
if the --no-tablespaces
option is not used. SELECT
权限,转储视图具有SHOW VIEW
权限,转储触发器具有TRIGGER
权限,如果不使用--single-transaction
选项,则需要LOCK TABLES
权限,如果未使用--no-tablespaces
选项,则(自MySQL 8.0.21起)需要PROCESS
权限。Certain options might require other privileges as noted in the option descriptions.某些选项可能需要其他权限,如选项描述中所述。
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.CREATE
权限。
mysqldump output can include mysqldump输出可以包含更改数据库排序规则的ALTER DATABASE
statements that change the database collation. ALTER DATABASE
语句。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.ALTER
权限。
A dump made using PowerShell on Windows with output redirection creates a file that has UTF-16 encoding:在Windows上使用带有输出重定向的PowerShell进行转储会创建一个具有UTF-16编码的文件:
mysqldump [options] > dump.sql
However, UTF-16 is not permitted as a connection character set (see Impermissible Client Character Sets), so the dump file cannot be loaded correctly. 但是,UTF-16不允许作为连接字符集(请参阅不允许的客户端字符集),因此无法正确加载转储文件。To work around this issue, use the 要解决此问题,请使用--result-file
option, which creates the output in ASCII format:--result-file
选项,该选项以ASCII格式创建输出:
mysqldump [options] --result-file=dump.sql
mysqldump
advantages include the convenience and flexibility of viewing or even editing the output before restoring. mysqldump
的优点包括在恢复之前查看甚至编辑输出的便利性和灵活性。You can clone databases for development and DBA work, or produce slight variations of an existing database for testing. 您可以克隆数据库以进行开发和DBA工作,也可以对现有数据库进行轻微修改以进行测试。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.它不是用于备份大量数据的快速或可扩展的解决方案。对于大数据量,即使备份步骤需要合理的时间,恢复数据也可能非常缓慢,因为重放SQL语句涉及插入、创建索引等的磁盘I/O。
For large-scale backup and restore, a physical backup is more appropriate, to copy the data files in their original format that can be restored quickly:对于大规模备份和还原,物理备份更为合适,以可以快速还原的原始格式复制数据文件:
If your tables are primarily 如果您的表主要是InnoDB
tables, or if you have a mix of InnoDB
and MyISAM
tables, consider using the mysqlbackup command of the MySQL Enterprise Backup product. (Available as part of the Enterprise subscription.) InnoDB
表,或者您有InnoDB
和MyISAM
表的混合,请考虑使用MySQL Enterprise Backup产品的mysqlbackup命令。(作为Enterprise订阅的一部分提供。)It provides the best performance for 它以最小的中断为InnoDB
backups with minimal disruption; it can also back up tables from MyISAM
and other storage engines; and it provides a number of convenient options to accommodate different backup scenarios. InnoDB
备份提供了最佳性能;它还可以备份MyISAM
和其他存储引擎的表;并且它提供了许多方便的选项来适应不同的备份场景。See Section 30.2, “MySQL Enterprise Backup Overview”.请参阅第30.2节,“MySQL企业备份概述”。
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. mysqldump可以逐行检索和转储表内容,也可以从表中检索整个内容,并在转储之前将其缓冲在内存中。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
). --quick
选项(或--opt
,它启用--quick
)。The 默认情况下启用了--opt
option (and hence --quick
) is enabled by default, so to enable memory buffering, use --skip-quick
.--opt
选项(因此也启用了--quick
),因此要启用内存缓冲,请使用--skip-quick
。
If you are using a recent version of mysqldump to generate a dump to be reloaded into a very old MySQL server, use the 如果您使用最新版本的mysqldump生成转储以重新加载到非常旧的MySQL服务器中,请使用--skip-opt
option instead of the --opt
or --extended-insert
option.--skip-opt
选项而不是--opt
或--extended-insert
选项。
For additional information about mysqldump, see Section 7.4, “Using mysqldump for Backups”.有关mysqldump的更多信息,请参阅第7.4节,“使用mysqldump进行备份”。
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——转储一组一个或多个表、一组完整的数据库或整个MySQL服务器——如下所示:
mysqldump [options
]db_name
[tbl_name
...] mysqldump [options
] --databasesdb_name
... mysqldump [options
] --all-databases
To dump entire databases, do not name any tables following 要转储整个数据库,请不要在db_name
, or use the --databases
or --all-databases
option.db_name
后面命名任何表,或使用--databases
或--all-databases
选项。
To see a list of the options your version of mysqldump supports, issue the command mysqldump --help.要查看您的mysqldump版本支持的选项列表,请发出命令mysqldump --help
。
mysqldump supports the following options, which can be specified on the command line or in the mysqldump支持以下选项,可以在命令行或选项文件的[mysqldump]
and [client]
groups of an option file. [mysqldump]
和[client]
组中指定。For information about option files used by MySQL programs, see Section 4.2.2.2, “Using Option Files”.有关MySQL程序使用的选项文件的信息,请参阅第4.2.2.2节,“使用选项文件”。
Table 4.14 mysqldump Options选项
--add-drop-database | CREATE DATABASE 语句之前添加DROP DATABASE 语句 | ||
---|---|---|---|
--add-drop-table | CREATE TABLE 语句之前添加DROP TABLE 语句 | ||
--add-drop-trigger | CREATE TRIGGER 语句之前添加DROP TRIGGER 语句 | ||
--add-locks | LOCK TABLES 和UNLOCK TABLES 语句包围每个表转储 | ||
--all-databases | |||
--allow-keywords | |||
--apply-slave-statements | CHANGE MASTER 语句之前包含STOP SLAVE ,并在输出末尾包含START SLAVE | ||
--bind-address | |||
--character-sets-dir | |||
--column-statistics | ANALYZE TABLE 语句以生成统计直方图 | ||
--comments | |||
--compact | |||
--compatible | |||
--complete-insert | |||
--compress | 8.0.18 | ||
--compression-algorithms | 8.0.18 | ||
--create-options | CREATE TABLE 语句中包含所有MySQL特定的表选项 | ||
--databases | |||
--debug | |||
--debug-check | |||
--debug-info | |||
--default-auth | |||
--default-character-set | |||
--defaults-extra-file | |||
--defaults-file | |||
--defaults-group-suffix | |||
--delete-master-logs | |||
--disable-keys | |||
--dump-date | |||
--dump-slave | CHANGE MASTER 语句,该语句列出了从属主机的二进制日志坐标 | ||
--enable-cleartext-plugin | |||
--events | |||
--extended-insert | INSERT 语法 | ||
--fields-enclosed-by | --tab 选项一起使用,其含义与LOAD DATA 的相应子句相同 | ||
--fields-escaped-by | --tab 选项一起使用,其含义与LOAD DATA 的相应子句相同 | ||
--fields-optionally-enclosed-by | LOAD DATA 的相应子句相同 | ||
--fields-terminated-by | LOAD DATA 的相应子句相同 | ||
--flush-logs | |||
--flush-privileges | FLUSH PRIVILES 语句 | ||
--force | |||
--get-server-public-key | |||
--help | |||
--hex-blob | |||
--host | |||
--ignore-error | |||
--ignore-table | |||
--include-master-host-port | --dump-slave 生成的CHANGE MASTER 语句中包含MASTER_HOST/MASTER_PORT 选项 | ||
--insert-ignore | INSERT IGNORE 而不是INSERT 语句 | ||
--lines-terminated-by | --tab 选项一起使用,其含义与LOAD DATA 的相应子句相同 | ||
--lock-all-tables | |||
--lock-tables | |||
--log-error | |||
--login-path | .mylogin.cnf 读取登录路径选项 | ||
--master-data | |||
--max-allowed-packet | |||
--net-buffer-length | |||
--network-timeout | |||
--no-autocommit | INSERT 语句包含在SET autocommit=0 和COMMIT 语句中 | ||
--no-create-db | CREATE DATABASE 语句 | ||
--no-create-info | CREATE TABLE 语句来重新创建每个转储的表 | ||
--no-data | |||
--no-defaults | |||
--no-set-names | --skip-set-charset 相同 | ||
--no-tablespaces | CREATE LOGFILE GROUP 或CREATE TABLESPACE 语句 | ||
--opt | --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset 的简写 | ||
--order-by-primary | |||
--password | |||
--pipe | |||
--plugin-dir | |||
--port | |||
--print-defaults | |||
--protocol | |||
--quick | |||
--quote-names | |||
--replace | REPLACE 语句而不是INSERT 语句 | ||
--result-file | |||
--routines | |||
--server-public-key-path | |||
--set-charset | SET NAMES default_character_set 添加到输出中 | ||
--set-gtid-purged | SET @@GLOBAL.GTID_PURGED 添加到输出 | ||
--shared-memory-base-name | |||
--show-create-skip-secondary-engine | CREATE TABLE 语句中排除SECONDARY ENGINE 子句 | 8.0.18 | |
--single-transaction | |||
--skip-add-drop-table | CREATE TABLE 语句之前添加DROP TABLE 语句 | ||
--skip-add-locks | |||
--skip-comments | |||
--skip-compact | |||
--skip-disable-keys | |||
--skip-extended-insert | |||
--skip-opt | --opt 设置的选项 | ||
--skip-quick | |||
--skip-quote-names | |||
--skip-set-charset | SET NAMES 语句 | ||
--skip-triggers | |||
--skip-tz-utc | |||
--socket | |||
--ssl-ca | |||
--ssl-capath | |||
--ssl-cert | |||
--ssl-cipher | |||
--ssl-crl | |||
--ssl-crlpath | |||
--ssl-fips-mode | |||
--ssl-key | |||
--ssl-mode | |||
--tab | |||
--tables | --databases 或-B 选项 | ||
--tls-ciphersuites | 8.0.16 | ||
--tls-version | |||
--triggers | |||
--tz-utc | SET TIME_ZONE='+00:00' 添加到转储文件 | ||
--user | |||
--verbose | |||
--version | |||
--where | WHERE 条件选择的行 | ||
--xml | |||
--zstd-compression-level | 8.0.18 |
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.mysqldump命令登录MySQL服务器以提取信息。以下选项指定了如何连接到MySQL服务器,无论是在同一台机器上还是在远程系统上。
On a computer having multiple network interfaces, use this option to select which interface to use for connecting to the MySQL server.在具有多个网络接口的计算机上,使用此选项选择用于连接MySQL服务器的接口。
Compress all information sent between the client and the server if possible. See Section 4.2.8, “Connection Compression Control”.如果可能的话,压缩客户端和服务器之间发送的所有信息。参阅第4.2.8节,“连接压缩控制”。
As of MySQL 8.0.18, this option is deprecated. Expect it to be removed in a future version of MySQL. See Configuring Legacy Connection Compression.从MySQL 8.0.18开始,此选项已被弃用。预计它将在MySQL的未来版本中被删除。请参阅配置传统连接压缩。
--compression-algorithms=
value
The permitted compression algorithms for connections to the server. The available algorithms are the same as for the 允许用于连接到服务器的压缩算法。可用的算法与protocol_compression_algorithms
system variable. protocol_compression_algorithms
系统变量的算法相同。The default value is 默认值为uncompressed
.uncompressed
。
For more information, see Section 4.2.8, “Connection Compression Control”.有关更多信息,请参阅第4.2.8节,“连接压缩控制”。
This option was added in MySQL 8.0.18.此选项是在MySQL 8.0.18中添加的。
A hint about which client-side authentication plugin to use. See Section 6.2.17, “Pluggable Authentication”.关于使用哪个客户端身份验证插件的提示。参阅第6.2.17节,“可插拔身份验证”。
Enable the 启用mysql_clear_password
cleartext authentication plugin. (See Section 6.4.1.4, “Client-Side Cleartext Pluggable Authentication”.)mysql_clear_password
明文身份验证插件。(参阅第6.4.1.4节,“客户端明文可插拔身份验证”。)
Request from the server the public key required for RSA key pair-based password exchange. 从服务器请求基于RSA密钥对的密码交换所需的公钥。This option applies to clients that authenticate with the 此选项适用于使用caching_sha2_password
authentication plugin. caching_sha2_password
身份验证插件进行身份验证的客户端。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.如果不使用基于RSA的密码交换,它也会被忽略,就像客户端使用安全连接连接到服务器的情况一样。
If 如果给定了--server-public-key-path=
is given and specifies a valid public key file, it takes precedence over file_name
--get-server-public-key
.--server-public-key-path=file_name
并指定了一个有效的公钥文件,则它优先于--get-server-public-key
。
For information about the 有关caching_sha2_password
plugin, see Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.caching_sha2_password
插件的信息,请参阅第6.4.1.2节,“缓存SHA-2可插拔身份验证”。
--host=
, host_name
-h
host_name
Dump data from the MySQL server on the given host. The default host is 从给定主机上的MySQL服务器转储数据。默认主机是localhost
.localhost
。
Read options from the named login path in the 从.mylogin.cnf
login path file. .mylogin.cnf
登录路径文件中的指定登录路径读取选项。A “login path” is an option group containing options that specify which MySQL server to connect to and which account to authenticate as. “登录路径”是一个选项组,其中包含指定要连接到哪个MySQL服务器以及要作为哪个帐户进行身份验证的选项。To create or modify a login path file, use the mysql_config_editor utility. 要创建或修改登录路径文件,请使用mysql_config_editor实用程序。See Section 4.6.7, “mysql_config_editor — MySQL Configuration Utility”.请参阅第4.6.7节,“mysql_config编辑器--mysql配置实用程序”。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
--password[=
, password
]-p[
password
]
The password of the MySQL account used for connecting to the server. 用于连接到服务器的MySQL帐户的密码。The password value is optional. If not given, mysqldump prompts for one. 密码值是可选的。如果没有给出,mysqldump会提示输入一个。If given, there must be no space between 如果给定,则--password=
or -p
and the password following it. If no password option is specified, the default is to send no password.--password=
或-p
与其后面的密码之间不得有空格。如果未指定密码选项,则默认情况下不发送密码。
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 6.1.2.1, “End-User Guidelines for Password Security”.在命令行上指定密码应被视为不安全。为了避免在命令行上输入密码,请使用选项文件。请参阅第6.1.2.1节,“密码安全最终用户指南”。
To explicitly specify that there is no password and that mysqldump should not prompt for one, use the 要明确指定没有密码并且mysqldump不应提示输入密码,请使用--skip-password
option.--skip-password
选项。
On Windows, connect to the server using a named pipe. 在Windows上,使用命名管道连接到服务器。This option applies only if the server was started with the 仅当服务器启动时启用了named_pipe
system variable enabled to support named-pipe connections. named_pipe
系统变量以支持命名管道连接时,此选项才适用。In addition, the user making the connection must be a member of the Windows group specified by the 此外,进行连接的用户必须是named_pipe_full_access_group
system variable.named_pipe_full_access_group
系统变量指定的Windows组的成员。
The directory in which to look for plugins. 查找插件的目录。Specify this option if the 如果使用--default-auth
option is used to specify an authentication plugin but mysqldump does not find it. See Section 6.2.17, “Pluggable Authentication”.--default-auth
选项指定身份验证插件,但mysqldump找不到它,请指定此选项。请参阅第6.2.17节,“可插拔身份验证”。
For TCP/IP connections, the port number to use.对于TCP/IP连接,要使用的端口号。
--protocol={TCP|SOCKET|PIPE|MEMORY}
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 4.2.7, “Connection Transport Protocols”.有关允许值的详细信息,请参阅第4.2.7节,“连接传输协议”。
--server-public-key-path=
file_name
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. PEM格式文件的路径名,该文件包含服务器基于RSA密钥对进行密码交换所需的公钥客户端副本。This option applies to clients that authenticate with the 此选项适用于使用sha256_password
or caching_sha2_password
authentication plugin. sha256_password
或caching_sha2_password
身份验证插件进行身份验证的客户端。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.对于未使用这些插件之一进行身份验证的帐户,此选项将被忽略。如果不使用基于RSA的密码交换,它也会被忽略,就像客户端使用安全连接连接到服务器的情况一样。
If 如果给定了--server-public-key-path=
is given and specifies a valid public key file, it takes precedence over file_name
--get-server-public-key
.--server-public-key-path=file_name
并指定了一个有效的公钥文件,则它优先于--get-server-public-key
。
For 对于sha256_password
, this option applies only if MySQL was built using OpenSSL.sha256_password
,此选项仅适用于使用OpenSSL构建MySQL的情况。
For information about the 有关sha256_password
and caching_sha2_password
plugins, see Section 6.4.1.3, “SHA-256 Pluggable Authentication”, and Section 6.4.1.2, “Caching SHA-2 Pluggable Authentication”.sha256_password
和caching_sha2_password
插件的信息,请参阅第6.4.1.3节,“SHA-256可插拔身份验证”和第6.4.1.2节,“缓存SHA-2可插拔身份认证”。
For connections to 对于与localhost
, the Unix socket file to use, or, on Windows, the name of the named pipe to use.localhost
的连接,使用Unix套接字文件,或者在Windows上,使用命名管道的名称。
On Windows, this option applies only if the server was started with the 在Windows上,此选项仅在服务器启动时启用了named_pipe
system variable enabled to support named-pipe connections. named_pipe
系统变量以支持命名管道连接时适用。In addition, the user making the connection must be a member of the Windows group specified by the 此外,进行连接的用户必须是named_pipe_full_access_group
system variable.named_pipe_full_access_group
系统变量指定的Windows组的成员。
Options that begin with 以--ssl
specify whether to connect to the server using encryption and indicate where to find SSL keys and certificates. See Command Options for Encrypted Connections.--ssl
开头的选项指定是否使用加密连接到服务器,并指示在哪里查找ssl密钥和证书。请参见加密连接的命令选项。
--ssl-fips-mode={OFF|ON|STRICT}
Controls whether to enable FIPS mode on the client side. 控制是否在客户端启用FIPS模式。The --ssl-fips-mode
option differs from other --ssl-
options in that it is not used to establish encrypted connections, but rather to affect which cryptographic operations to permit. xxx
--ssl-fips-mode
选项与其他--ssl-xxx
选项的不同之处在于,它不用于建立加密连接,而是影响允许的加密操作。See Section 6.8, “FIPS Support”.请参阅第6.8节,“FIPS支持”。
These 允许使用以下--ssl-fips-mode
values are permitted:--ssl-fips-mode
值:
OFF
: Disable FIPS mode.:禁用FIPS模式。
ON
: Enable FIPS mode.:启用FIPS模式。
STRICT
: Enable “strict” FIPS mode.:启用“严格”FIPS模式。
If the OpenSSL FIPS Object Module is not available, the only permitted value for 如果OpenSSL FIPS对象模块不可用,则--ssl-fips-mode
is OFF
. --ssl-fips-mode
的唯一允许值为OFF
。In this case, setting 在这种情况下,将--ssl-fips-mode
to ON
or STRICT
causes the client to produce a warning at startup and to operate in non-FIPS mode.--ssl-fips-mode
设置为ON
或STRICT
会导致客户端在启动时产生警告,并在非fips模式下运行。
--tls-ciphersuites=
ciphersuite_list
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. 允许的密码适用于使用TLSv1.3的加密连接。该值是一个或多个冒号分隔的密码套件名称的列表。可以为此选项命名的密码套件取决于用于编译MySQL的SSL库。For details, see Section 6.3.2, “Encrypted Connection TLS Protocols and Ciphers”.有关详细信息,请参阅第6.3.2节,“加密连接TLS协议和密码”。
This option was added in MySQL 8.0.16.此选项是在MySQL 8.0.16中添加的。
The permissible TLS protocols for encrypted connections. The value is a list of one or more comma-separated protocol names. 加密连接的允许TLS协议。该值是一个或多个逗号分隔的协议名称的列表。The protocols that can be named for this option depend on the SSL library used to compile MySQL. 可以为此选项命名的协议取决于用于编译MySQL的SSL库。For details, see Section 6.3.2, “Encrypted Connection TLS Protocols and Ciphers”.有关详细信息,请参阅第6.3.2节,“加密连接TLS协议和密码”。
--user=
, user_name
-u
user_name
The user name of the MySQL account to use for connecting to the server.用于连接到服务器的MySQL帐户的用户名。
--zstd-compression-level=
level
The compression level to use for connections to the server that use the 用于连接到使用zstd
compression algorithm. zstd
压缩算法的服务器的压缩级别。The permitted levels are from 1 to 22, with larger values indicating increasing levels of compression. 允许的级别为1到22,较大的值表示压缩级别增加。The default 默认的zstd
compression level is 3. zstd
压缩级别为3。The compression level setting has no effect on connections that do not use 压缩级别设置对不使用zstd
compression.zstd
压缩的连接没有影响。
For more information, see Section 4.2.8, “Connection Compression Control”.有关更多信息,请参阅第4.2.8节,“连接压缩控制”。
This option was added in MySQL 8.0.18.此选项是在MySQL 8.0.18中添加的。
These options are used to control which option files to read.这些选项用于控制要读取的选项文件。
--defaults-extra-file=
file_name
Read this option file after the global option file but (on Unix) before the user option file. 在全局选项文件之后读取此选项文件,但(在Unix上)在用户选项文件之前读取。If the file does not exist or is otherwise inaccessible, an error occurs. If 如果文件不存在或无法访问,则会发生错误。如果file_name
is not an absolute path name, it is interpreted relative to the current directory.file_name
不是绝对路径名,则会相对于当前目录进行解释。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs. If 仅使用给定的选项文件。如果文件不存在或无法访问,则会发生错误。如果file_name
is not an absolute path name, it is interpreted relative to the current directory.file_name
不是绝对路径名,则会相对于当前目录进行解释。
Exception: Even with 异常:即使使用--defaults-file
, client programs read .mylogin.cnf
.--defaults-file
,客户端程序也会读取.mylogin.cnf
。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
Read not only the usual option groups, but also groups with the usual names and a suffix of 不仅要读取常用的选项组,还要读取具有常用名称和后缀str
. str
的组。For example, mysqldump normally reads the 例如,mysqldump通常读取[client]
and [mysqldump]
groups. [client]
和[mysqldump]
组。If this option is given as 如果将此选项设置为--defaults-group-suffix=_other
, mysqldump also reads the [client_other]
and [mysqldump_other]
groups.--defaults-group-suffix=_other
,mysqldump也会读取[client_other]
和[mysqldump_other]
组。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
Do not read any option files. If program startup fails due to reading unknown options from an option file, 不要读取任何选项文件。如果程序启动因从选项文件中读取未知选项而失败,则使用--no-defaults
can be used to prevent them from being read.--no-defaults
来阻止读取它们。
The exception is that the 例外的是,.mylogin.cnf
file is read in all cases, if it exists. .mylogin.cnf
文件在所有情况下都会被读取(如果存在的话)。This permits passwords to be specified in a safer way than on the command line even when 这允许以比命令行更安全的方式指定密码,即使使用--no-defaults
is used. --no-defaults
。To create 要创建.mylogin.cnf
, use the mysql_config_editor utility. .mylogin.cnf
,请使用mysql_config_editor实用程序。See Section 4.6.7, “mysql_config_editor — MySQL Configuration Utility”.请参阅第4.6.7节,“mysql_config编辑器--mysql配置实用程序”。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
Print the program name and all options that it gets from option files.打印程序名称及其从选项文件中获取的所有选项。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
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. mysqldump的使用场景包括设置一个全新的MySQL实例(包括数据库表),以及用现有的数据库和表替换现有实例中的数据。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.以下选项允许您通过在转储文件中编码各种DDL语句来指定在还原转储时要删除和设置哪些内容。
Write a 在每条DROP DATABASE
statement before each CREATE DATABASE
statement. CREATE DATABASE
语句之前写一条DROP DATABASE
语句。This option is typically used in conjunction with the 此选项通常与--all-databases
or --databases
option because no CREATE DATABASE
statements are written unless one of those options is specified.--all-databases
或--databases
选项结合使用,因为除非指定了其中一个选项,否则不会编写CREATE DATABASE
语句。
In MySQL 8.0, the 在MySQL 8.0中,mysql模式被认为是最终用户不能删除的系统模式。mysql
schema is considered a system schema that cannot be dropped by end users. If 如果--add-drop-database
is used with --all-databases
or with --databases
where the list of schemas to be dumped includes mysql
, the dump file contains a DROP DATABASE `mysql`
statement that causes an error when the dump file is reloaded.--add-drop-database
与--all-databases
或与--databases
一起使用,其中要转储的模式列表包括mysql,则转储文件包含一个DROP DATABASE `mysql`
语句,该语句在重新加载转储文件时会导致错误。
Instead, to use 相反,要使用--add-drop-database
, use --databases
with a list of schemas to be dumped, where the list does not include mysql
.--add-drop-database
,请使用带有要转储的模式列表的数据库,其中列表不包括mysql。
Write a 在每个DROP TABLE
statement before each CREATE TABLE
statement.CREATE TABLE
语句之前写一个DROP TABLE
语句。
Write a 在每个DROP TRIGGER
statement before each CREATE TRIGGER
statement.CREATE TRIGGER
语句之前写一个DROP TRIGGER
语句。
Adds to a table dump all SQL statements needed to create any tablespaces used by an 将创建NDB
table. NDB
表使用的任何表空间所需的所有SQL语句添加到表转储中。This information is not otherwise included in the output from mysqldump. This option is currently relevant only to NDB Cluster tables.此信息不会以其他方式包含在mysqldump的输出中。此选项目前仅与NDB群集表相关。
Suppress the 如果给出了CREATE DATABASE
statements that are otherwise included in the output if the --databases
or --all-databases
option is given.--databases
或--all-databases
选项,则禁止输出中包含的CREATE DATABASE
语句。
Do not write 不要编写创建每个转储表的CREATE TABLE
statements that create each dumped table.CREATE TABLE
语句。
This option does not exclude statements creating log file groups or tablespaces from mysqldump output; however, you can use the 此选项不排除从mysqldump输出中创建日志文件组或表空间的语句;但是,您可以为此使用--no-tablespaces
option for this purpose.--no-tablespaces
选项。
This option suppresses all 此选项会抑制mysqldump输出中的所有CREATE LOGFILE GROUP
and CREATE TABLESPACE
statements in the output of mysqldump.CREATE LOGFILE GROUP
和CREATE TABLESPACE
语句。
Write 写REPLACE
statements rather than INSERT
statements.REPLACE
语句而不是INSERT
语句。
The following options print debugging information, encode debugging information in the dump file, or let the dump operation proceed regardless of potential problems.以下选项可以打印调试信息,在转储文件中编码调试信息,或者让转储操作继续进行,而不管潜在的问题。
Permit creation of column names that are keywords. This works by prefixing each column name with the table name.允许创建关键字列名。这是通过在每个列名前加上表名来实现的。
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
.--skip-comments
。
--debug[=
, debug_options
]-# [
debug_options
]
Write a debugging log. A typical 编写调试日志。典型的debug_options
string is d:t:o,
. The default value is file_name
d:t:o,/tmp/mysqldump.trace
.debug_options
字符串是d:t:o,file_name
。默认值为d:t:o,/tmp/mysqldump.trace
。
This option is available only if MySQL was built using 仅当MySQL使用WITH_DEBUG
. MySQL release binaries provided by Oracle are not built using this option.WITH_DEBUG
构建时,此选项才可用。Oracle提供的MySQL发布二进制文件不是使用此选项构建的。
Print some debugging information when the program exits.程序退出时打印一些调试信息。
This option is available only if MySQL was built using 仅当MySQL使用WITH_DEBUG
. MySQL release binaries provided by Oracle are not built using this option.WITH_DEBUG
构建时,此选项才可用。Oracle提供的MySQL发布二进制文件不是使用此选项构建的。
Print debugging information and memory and CPU usage statistics when the program exits.程序退出时打印调试信息以及内存和CPU使用统计数据。
This option is available only if MySQL was built using 仅当MySQL使用WITH_DEBUG
. WITH_DEBUG
构建时,此选项才可用。MySQL release binaries provided by Oracle are not built using this option.Oracle提供的MySQL发布二进制文件不是使用此选项构建的。
If the 如果给出了--comments
option is given, mysqldump produces a comment at the end of the dump of the following form:--comments
选项,mysqldump将在转储末尾生成以下形式的注释:
-- Dump completed on DATE
However, the date causes dump files taken at different times to appear to be different, even if the data are otherwise identical. 然而,即使数据在其他方面是相同的,日期也会导致在不同时间拍摄的转储文件看起来不同。--dump-date
and --skip-dump-date
control whether the date is added to the comment. --dump-date
和--skip-dump-date
控制是否将日期添加到注释中。The default is 默认值是--dump-date
(include the date in the comment). --skip-dump-date
suppresses date printing.--dump-date
(在注释中包含日期)。--skip-dump-date
会抑制日期打印。
Ignore all errors; continue even if an SQL error occurs during a table dump.忽略所有错误;即使在表转储过程中发生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. 此选项的一个用途是使mysqldump继续执行,即使它遇到一个因定义引用了已删除的表而无效的视图。Without 如果没有--force
, mysqldump exits with an error message. --force
,mysqldump将退出并显示错误消息。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.--force
,mysqldump会打印错误消息,但它也会将包含视图定义的SQL注释写入转储输出并继续执行。
If the 如果还提供了--ignore-error
option is also given to ignore specific errors, --force
takes precedence.--ignore-error
选项来忽略特定错误,则--force
优先。
Log warnings and errors by appending them to the named file. The default is to do no logging.通过将警告和错误附加到指定文件来记录它们。默认设置是不进行日志记录。
See the description for the 请参阅--comments
option.--comments
选项的说明。
Verbose mode. Print more information about what the program does.详细模式。打印有关程序功能的更多信息。
The following options display information about the mysqldump command itself.以下选项显示有关mysqldump命令本身的信息。
The following options change how the mysqldump command represents character data with national language settings.以下选项更改mysqldump命令使用国家语言设置表示字符数据的方式。
The directory where character sets are installed. 安装字符集的目录。See Section 10.15, “Character Set Configuration”.
--default-character-set=
charset_name
Use 使用charset_name
as the default character set. charset_name
作为默认字符集。See Section 10.15, “Character Set Configuration”. 请参阅第10.15节,“字符集配置”。If no character set is specified, mysqldump uses 如果没有指定字符集,mysqldump将使用utf8
.utf8
。
Turns off the 关闭--set-charset
setting, the same as specifying --skip-set-charset
.--set-charset
设置,与指定--skip-set-charset
相同。
Write 将SET NAMES
to the output. This option is enabled by default. default_character_set
SET NAMES default_character_set
写入输出。默认情况下启用此选项。To suppress the 要抑制SET NAMES
statement, use --skip-set-charset
.SET NAMES
语句,请使用--skip-set-charset
。
The mysqldump command is frequently used to create an empty instance, or an instance including data, on a replica server in a replication configuration. mysqldump命令经常用于在复制配置中的副本服务器上创建空实例或包含数据的实例。The following options apply to dumping and restoring data on replication source servers and replicas.以下选项适用于在复制源服务器和副本上转储和还原数据。
For a replica dump produced with the 对于使用--dump-slave
option, add a STOP REPLICA | SLAVE
statement before the statement with the binary log coordinates, and a START REPLICA | SLAVE
statement at the end of the output.--dump-slave
选项生成的副本转储,请在具有二进制日志坐标的语句之前添加STOP REPLICA | SLAVE
语句,并在输出末尾添加START REPLICA | SLAVE
语句。
On a replication source server, delete the binary logs by sending a 在复制源服务器上,执行转储操作后,通过向服务器发送PURGE BINARY LOGS
statement to the server after performing the dump operation. PURGE BINARY LOGS
语句来删除二进制日志。This option requires the 此选项需要RELOAD
privilege as well as privileges sufficient to execute that statement. RELOAD
权限以及足以执行该语句的权限。This option automatically enables 此选项会自动启用--master-data
.--master-data
。
This option is similar to 此选项类似于--master-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. --master-data
,除了它用于转储副本服务器以生成转储文件,该转储文件可用于将另一台服务器设置为与转储服务器具有相同源的副本。It causes the dump output to include a 它会导致转储输出包含CHANGE REPLICATION SOURCE TO
statement (from MySQL 8.0.23) or CHANGE MASTER TO
statement (before MySQL 8.0.23) that indicates the binary log coordinates (file name and position) of the dumped replica's source. CHANGE REPLICATION SOURCE TO
语句(来自MySQL 8.0.23)或CHANGE MASTER TO
语句(MySQL 8.0.22之前),用于指示转储副本源的二进制日志坐标(文件名和位置)。The CHANGE REPLICATION SOURCE TO
statement reads the values of Relay_Master_Log_File
and Exec_Master_Log_Pos
from the SHOW REPLICA | SLAVE STATUS
output and uses them for SOURCE_LOG_FILE
and SOURCE_LOG_POS
respectively. CHANGE REPLICATION SOURCE TO
语句从SHOW REPLICA | SLAVE STATUS
输出中读取Relay_Master_Log_File
和Exec_Master_Log_Pos
的值,并将其分别用于SOURCE_LOG_FILE
和SOURCE_LOG_POS
。These are the replication source server coordinates from which the replica starts replicating.这些是复制副本开始复制的复制源服务器坐标。
Inconsistencies in the sequence of transactions from the relay log which have been executed can cause the wrong position to be used. See Section 17.5.1.34, “Replication and Transaction Inconsistencies” for more information.已执行的中继日志中的事务顺序不一致可能会导致使用错误的位置。有关更多信息,请参阅第17.5.1.34节,“复制和事务不一致”。
--dump-slave
causes the coordinates from the source to be used rather than those of the dumped server, as is done by the --master-data
option. In addition, specifiying this option causes the --master-data
option to be overridden, if used, and effectively ignored.--dump-slave
会使用源的坐标,而不是转储服务器的坐标,就像--master-data
选项所做的那样。此外,指定此选项会导致--master-data
选项被覆盖(如果使用),并实际上被忽略。
This option should not be used if the server where the dump is going to be applied uses 如果要应用转储的服务器使用gtid_mode=ON
and MASTER_AUTOPOSITION=1
.gtid_mode=ON
和MASTER_AUTOPITION=1
,则不应使用此选项。
The option value is handled the same way as for 选项值的处理方式与--master-data
. --master-data
相同。Setting no value or 1 causes a 不设置值或设置1会导致将CHANGE REPLICATION SOURCE TO
statement (from MySQL 8.0.23) or CHANGE MASTER TO
statement (before MySQL 8.0.23) to be written to the dump. CHANGE REPLICATION SOURCE TO
语句(来自MySQL 8.0.23)或CHANGE MASTER TO
语句(MySQL 8.0.22之前)写入转储。Setting 2 causes the statement to be written but encased in SQL comments. 设置2会导致语句被写入,但被封装在SQL注释中。It has the same effect as 在启用或禁用其他选项以及如何处理锁定方面,它与--master-data
in terms of enabling or disabling other options and in how locking is handled.--master-data
具有相同的效果。
This option causes mysqldump to stop the replication SQL thread before the dump and restart it again after.此选项会导致mysqldump在转储之前停止复制SQL线程,并在转储之后再次重新启动。
--dump-slave
sends a SHOW REPLICA | SLAVE STATUS
statement to the server to obtain information, so it requires privileges sufficient to execute that statement.--dump-slave
向服务器发送SHOW REPLICA | SLAVE STATUS
语句以获取信息,因此它需要足够的权限来执行该语句。
In conjunction with 结合--dump-slave
, the --apply-slave-statements
and --include-master-host-port
options can also be used.--dump-slave
,还可以使用--apply-slave-statements
和--include-master-host-port
选项。
For the 对于使用CHANGE REPLICATION SOURCE TO
statement (from MySQL 8.0.23) or CHANGE MASTER TO
statement (before MySQL 8.0.23) in a replica dump produced with the --dump-slave
option, add SOURCE_HOST
| MASTER_HOST
and SOURCE_PORT
| MASTER_PORT
options for the host name and TCP/IP port number of the replica's source.--dump-slave
选项生成的副本转储中的CHANGE REPLICATION SOURCE TO
语句(来自MySQL 8.0.23)或CHANGE MASTER TO
语句(MySQL 8.0.22之前),为副本源的主机名和TCP/IP端口号添加SOURCE_HOST | MASTER_HOST
和SOURCE_PORT | MASTER_PORT
选项。
Use this option 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. 使用此选项转储复制源服务器以生成转储文件,该文件可用于将另一台服务器设置为源的副本。It causes the dump output to include a 它会导致转储输出包含CHANGE REPLICATION SOURCE TO
statement (from MySQL 8.0.23) or CHANGE MASTER TO
statement (before MySQL 8.0.23) that indicates the binary log coordinates (file name and position) of the dumped server. CHANGE REPLICATION SOURCE TO
语句(来自MySQL 8.0.23)或CHANGE MASTER TO
语句(MySQL 8.0.22之前),用于指示转储服务器的二进制日志坐标(文件名和位置)。These are the replication source server coordinates from which the replica should start replicating after you load the dump file into the replica.这些是复制源服务器坐标,在将转储文件加载到副本中后,副本应从这些坐标开始复制。
If the option value is 2, the 如果选项值为2,则CHANGE REPLICATION SOURCE TO
| CHANGE MASTER TO
statement is written as an SQL comment, and thus is informative only; it has no effect when the dump file is reloaded. CHANGE REPLICATION SOURCE TO
| CHANGE MASTER TO
语句将作为SQL注释编写,因此仅供参考;当转储文件被重新加载时,它没有任何效果。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.如果选项值为1,则语句不会作为注释写入,并在重新加载转储文件时生效。如果未指定选项值,则默认值为1。
--master-data
sends a SHOW MASTER STATUS
statement to the server to obtain information, so it requires privileges sufficient to execute that statement. This option also requires the RELOAD
privilege and the binary log must be enabled.--master-data
向服务器发送SHOW MASTER STATUS
语句以获取信息,因此它需要足够的权限来执行该语句。此选项还需要RELOAD
权限,并且必须启用二进制日志。
The --master-data
option automatically turns off --lock-tables
. --master-data
选项会自动关闭--lock-tables
。It also turns on 它还打开--lock-all-tables
, unless --single-transaction
also is specified, in which case, a global read lock is acquired only for a short time at the beginning of the dump (see the description for --single-transaction
). --lock-all-tables
,除非还指定了--single-transaction
,在这种情况下,在转储开始时只会在短时间内获取全局读取锁(请参阅--single-transaction
的描述)。In all cases, any action on logs happens at the exact moment of the dump.在所有情况下,对日志的任何操作都发生在转储的确切时刻。
It is also possible to set up a replica by dumping an existing replica of the source, using the 还可以通过使用--dump-slave
option, which overrides --master-data
and causes it to be ignored if both options are used.--dump-slave
选项转储源的现有副本来设置副本,该选项会覆盖--master-data
,如果同时使用这两个选项,则会忽略它。
This option is for servers that use GTID-based replication (此选项适用于使用基于GTID的复制(gtid_mode=ON
). GTID_mode=ON
)的服务器。It controls the inclusion of a 它控制在转储输出中包含SET @@GLOBAL.gtid_purged
statement in the dump output, which updates the value of gtid_purged
on a server where the dump file is reloaded, to add the GTID set from the source server's gtid_executed
system variable. SET @@GLOBAL.gtid_purged
语句,该语句在重新加载转储文件的服务器上更新gtid_prushed
的值,以从源服务器的gtid_executed
系统变量中添加GTID集。gtid_purged
holds the GTIDs of all transactions that have been applied on the server, but do not exist on any binary log file on the server. gtid_purged
保存服务器上已应用的所有事务的gtid,但不存在于服务器上的任何二进制日志文件中。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. 因此,mysqldump会为源服务器上执行的事务添加GTID,以便目标服务器在应用时记录这些事务,尽管它的二进制日志中没有这些事务。--set-gtid-purged
also controls the inclusion of a SET @@SESSION.sql_log_bin=0
statement, which disables binary logging while the dump file is being reloaded. --set-gtid-purged
还控制SET @@SESSION.sql_log_bin=0
语句的包含,该语句在重新加载转储文件时禁用二进制日志记录。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.此语句可防止在执行转储文件中的事务时生成新的GTID并将其分配给事务,从而使用事务的原始GTID。
If you do not set the 如果不设置--set-gtid-purged
option, the default is that a SET @@GLOBAL.gtid_purged
statement 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 the gtid_executed
system variable is not empty. --set-gtid-purged
选项,默认情况下,如果在要备份的服务器上启用了GTID,并且gtid_executed
系统变量的全局值中的gtid集不为空,则转储输出中会包含SET @@GLOBAL.gtid_purged
语句。A 如果服务器上启用了GTID,则还包括SET @@SESSION.sql_log_bin=0
statement is also included if GTIDs are enabled on the server.SET @@SESSION.sql_log_bin=0
语句。
In MySQL 5.6 and 5.7, you can replace the value of 在MySQL 5.6和5.7中,您可以用指定的GTID集替换gtid_purged
with a specified GTID set, provided that gtid_executed
and gtid_purged
are empty. gtid_purged
的值,前提是gtid_executed
和gtid_prused
为空。From MySQL 8.0, you can either replace the value of 在MySQL 8.0中,您可以将gtid_purged
with a specified GTID set, or you can add a plus sign (+) to the statement to append a specified GTID set to the GTID set that is already held by gtid_purged
. gtid_purged
的值替换为指定的GTID集,也可以在语句中添加加号(+),将指定的GTD集附加到gtid_prused
已持有的GTID集中。mysqldump's mysqldump的SET @@GLOBAL.gtid_purged
statement includes a plus sign (+) in a version comment that takes effect when the dump file is replayed on releases from MySQL 8.0, meaning that for these releases, the GTID set from the dump file is added to the existing gtid_purged
value. SET @@GLOBAL.gtid_purged
语句在版本注释中包含一个加号(+),该加号在MySQL 8.0的版本上重放转储文件时生效,这意味着对于这些版本,转储文件中设置的GTID将添加到现有的gtid_purged
值中。For MySQL 5.6 and 5.7, the value of 对于MySQL 5.6和5.7,gtid_purged
is replaced with the GTID set from the dump file, which can only happen when gtid_executed
is the empty set (so when replication has not been started previously, or when replication was not previously using GTIDs). gtid_purged
的值被转储文件中的GTID集替换,这只能在gtid_executed
为空集时发生(因此,当复制之前没有启动,或者复制之前没有使用GTID时)。For the exact details of how the 有关SET @@GLOBAL.gtid_purged
statement operates, see the gtid_purged
description for the release where the dump file is to be replayed.SET @@GLOBAL.gtid_purged
语句如何操作的确切详细信息,请参阅要重放转储文件的版本的gtid_purged
描述。
It is important to note that the value that is included by mysqldump for the 值得注意的是,mysqldump为SET @@GLOBAL.gtid_purged
statement includes the GTIDs of all transactions in the gtid_executed
set 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. SET @@GLOBAL.gtid_purged
语句包含的值包括服务器上gtid_executed
集中所有事务的GTID,即使是那些更改了数据库被抑制部分的事务,或服务器上未包含在部分转储中的其他数据库。This can mean that after the 这可能意味着,在重播转储文件的服务器上更新了gtid_purged
value 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. gtid_purged
值后,会出现与目标服务器上的任何数据都不相关的GTID。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. 如果不在目标服务器上重放任何进一步的转储文件,则无关的GTID不会对服务器的未来操作造成任何问题,但它们会使比较或协调复制拓扑中不同服务器上的GTID集变得更加困难。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), any 如果在目标服务器上重播包含相同GTID的另一个转储文件(例如,来自同一源服务器的另一部分转储),则第二个转储文件中的任何SET @@GLOBAL.gtid_purged
statement in the second dump file fails. SET @@GLOBAL.gtid_purged
语句都会失败。In this case, either remove the statement manually before replaying the dump file, or output the dump file without the statement.在这种情况下,在重放转储文件之前手动删除该语句,或者输出不包含该语句的转储文件。
For MySQL 5.6 and 5.7, it is not recommended to load a dump file when GTIDs are enabled on the server (对于MySQL 5.6和5.7,如果转储文件包含系统表,则不建议在服务器上启用gtid(gtid_mode=ON
), if your dump file includes system tables. gtid_mode=ON
)时加载转储文件。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.mysqldump为使用非事务性MyISAM
存储引擎的系统表发出DML指令,启用GTID时不允许这种组合。
If the 如果SET @@GLOBAL.gtid_purged
statement would not have the desired result on your target server, you can exclude the statement from the output, or (from MySQL 8.0.17) include it but comment it out so that it is not actioned automatically. SET @@GLOBAL.gtid_purged
语句在目标服务器上没有得到所需的结果,您可以从输出中排除该语句,或者(从MySQL 8.0.17中)包含它但将其注释掉,这样它就不会自动执行。You can also include the statement but manually edit it in the dump file to achieve the desired result.您还可以包含该语句,但要在转储文件中手动编辑它以实现所需的结果。
The possible values for the --set-gtid-purged
option are as follows:--set-gtid-purged
选项的可能值如下:
AUTO
The default value. 默认值。If GTIDs are enabled on the server you are backing up and 如果您正在备份的服务器上启用了GTID,并且gtid_executed
is not empty, SET @@GLOBAL.gtid_purged
is added to the output, containing the GTID set from gtid_executed
. gtid_executed
不为空,则SET @@GLOBAL.gtid_purged
将添加到输出中,其中包含gtid_excuted
中设置的GTID。If GTIDs are enabled, 如果启用了GTID,则将SET @@SESSION.sql_log_bin=0
is added to the output. SET @@SESSION.sql_log_bin=0
添加到输出中。If GTIDs are not enabled on the server, the statements are not added to the output.如果服务器上未启用GTID,则语句不会添加到输出中。
OFF
SET @@GLOBAL.gtid_purged
is not added to the output, and SET @@SESSION.sql_log_bin=0
is not added to the output. SET @@GLOBAL.gtid_purged
不会添加到输出中,SET@@SESSIONsql_log_bin=0也不会添加到输入中。For a server where GTIDs are not in use, use this option or 对于不使用GTID的服务器,请使用此选项或AUTO
. AUTO
。Only use this option for a server where GTIDs are in use if you are sure that the required GTID set is already present in 仅当您确定目标服务器上的gtid_purged
on the target server and should not be changed, or if you plan to identify and add any missing GTIDs manually.gtid_purged
中已经存在所需的GTID集并且不应更改,或者您计划手动识别和添加任何缺失的GTID时,才对使用GTID的服务器使用此选项。
ON
If GTIDs are enabled on the server you are backing up, 如果在要备份的服务器上启用了GTID,则SET @@GLOBAL.gtid_purged
is added to the output (unless gtid_executed
is empty), and SET @@SESSION.sql_log_bin=0
is added to the output. SET @@GLOBAL.gtid_purged
将添加到输出中(除非gtid_executed
为空),SET @@SESSION.sql_log_bin=0
将添加到输入中。An error occurs if you set this option but GTIDs are not enabled on the server. 如果设置了此选项,但服务器上未启用GTID,则会发生错误。For a server where GTIDs are in use, use this option or 对于使用gtid的服务器,请使用此选项或AUTO
, unless you are sure that the GTIDs in gtid_executed
are not needed on the target server.AUTO
,除非您确定目标服务器上不需要gtid_executed
中的GTID。
COMMENTED
Available from MySQL 8.0.17. If GTIDs are enabled on the server you are backing up, 可从MySQL 8.0.17获得。如果您正在备份的服务器上启用了gtid,则SET @@GLOBAL.gtid_purged
is added to the output (unless gtid_executed
is empty), but it is commented out. SET @@GLOBAL.gtid_purged
将添加到输出中(除非gtid_executed
为空),但会被注释掉。This means that the value of 这意味着gtid_executed
is available in the output, but no action is taken automatically when the dump file is reloaded. gtid_executed
的值在输出中可用,但在重新加载转储文件时不会自动采取任何行动。SET @@SESSION.sql_log_bin=0
is added to the output, and it is not commented out. SET @@SESSION.sql_log_bin=0
被添加到输出中,并且不会被注释掉。With 使用COMMENTED,您可以手动或通过自动化控制COMMENTED
, you can control the use of the gtid_executed
set manually or through automation. gtid_executed
集的使用。For example, you might prefer to do this if you are migrating data to another server that already has different active databases.例如,如果要将数据迁移到已经具有不同活动数据库的另一台服务器,您可能更喜欢这样做。
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.以下选项指定了如何表示整个转储文件或转储文件中的某些类型的数据。它们还控制是否将某些可选信息写入转储文件。
Produce more compact output. 生产更紧凑的输出。This option enables the 此选项启用--skip-add-drop-table
, --skip-add-locks
, --skip-comments
, --skip-disable-keys
, and --skip-set-charset
options.--skip-add-drop-table
、--skip-add-locks
、--skip-comments
、--skip-disable-keys
和--skip-set-charset
选项。
Produce output that is more compatible with other database systems or with older MySQL servers. 生成与其他数据库系统或旧MySQL服务器更兼容的输出。The only permitted value for this option is 此选项的唯一允许值是ansi
, which has the same meaning as the corresponding option for setting the server SQL mode. See Section 5.1.11, “Server SQL Modes”.ansi
,其含义与设置服务器SQL模式的相应选项相同。请参阅第5.1.11节,“服务器SQL模式”。
Use complete 使用包含列名的完整INSERT
statements that include column names.INSERT
语句。
Include all MySQL-specific table options in the 在CREATE TABLE
statements.CREATE TABLE
语句中包含所有MySQL特定的表选项。
--fields-terminated-by=...
, --fields-enclosed-by=...
, --fields-optionally-enclosed-by=...
, --fields-escaped-by=...
These options are used with the 这些选项与--tab
option and have the same meaning as the corresponding FIELDS
clauses for LOAD DATA
. --tab
选项一起使用,与LOAD DATA
的相应FIELDS
子句具有相同的含义。See Section 13.2.7, “LOAD DATA Statement”.请参阅第13.2.7节,“LOAD DATA语句”。
Dump binary columns using hexadecimal notation (for example, 使用十六进制表示法转储二进制列(例如,'abc'
becomes 0x616263
). 'abc'
变为0x616263
)。The affected data types are 当与二进制字符集一起使用时,受影响的数据类型包括BINARY
, VARBINARY
, BLOB
types, BIT
, all spatial data types, and other non-binary data types when used with the binary
character set.BINARY
、VARBINARY
、BLOB
类型、BIT
、所有空间数据类型和其他非二进制数据类型。
This option is used with the 此选项与--tab
option and has the same meaning as the corresponding LINES
clause for LOAD DATA
. --tab
选项一起使用,其含义与LOAD DATA
的相应LINES
子句相同。See Section 13.2.7, “LOAD DATA Statement”.请参阅第13.2.7节,“LOAD DATA语句”。
Quote identifiers (such as database, table, and column names) within 在`
characters. `
字符内引用标识符(如数据库、表和列名)。If the 如果启用ANSI_QUOTES
SQL mode is enabled, identifiers are quoted within "
characters. This option is enabled by default. ANSI_QUOTES
SQL模式,标识符将在"
字符内引用。默认情况下启用此选项。It can be disabled with 可以使用--skip-quote-names
, but this option should be given after any option such as --compatible
that may enable --quote-names
.--skip-quote-names
禁用它,但此选项应在任何选项(如可能启用--quote-names
的--compatible
)之后给出。
--result-file=
, file_name
-r
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.直接输出到指定文件。即使在生成转储时发生错误,也会创建结果文件并覆盖其先前的内容。
This option should be used on Windows to prevent newline 应在Windows上使用此选项,以防止换行符\n
characters from being converted to \r\n
carriage return/newline sequences.\n
转换为回车符/换行符\r\n
序列。
--show-create-skip-secondary-engine=
value
Excludes the 从SECONDARY ENGINE
clause from CREATE TABLE
statements. CREATE TABLE
语句中排除SECONDARY ENGINE
子句。It does so by enabling the 它通过在转储操作期间启用show_create_table_skip_secondary_engine
system variable for the duration of the dump operation. show_create_table_skip_secondary_engine
系统变量来实现。Alternatively, you can enable the 或者,您可以在使用mysqldump之前启用show_create_table_skip_secondary_engine
system variable prior to using mysqldump.show_create_table_skip_secondary_engine
系统变量。
This option was added in MySQL 8.0.18. Attempting a mysqldump operation with the 此选项是在MySQL 8.0.18中添加的。在MySQL 8.0.18之前的版本上尝试使用--show-create-skip-secondary-engine
option on a release prior to MySQL 8.0.18 that does not support the show_create_table_skip_secondary_engine
variable causes an error.--show-create-skip-secondary-engine
选项执行mysqldump操作,如果该版本不支持show_create_table_skip_secondary_engine
变量,则会导致错误。
Produce tab-separated text-format data files. 生成以制表符分隔的文本格式数据文件。For each dumped table, mysqldump creates a 对于每个转储的表,mysqldump都会创建一个
file that contains the tbl_name
.sqlCREATE TABLE
statement that creates the table, and the server writes a
file that contains its data. tbl_name
.txttbl_name.sql
文件,其中包含创建表的CREATE TABLE
语句,服务器会写入一个包含其数据的tbl_name.txt
文件。The option value is the directory in which to write the files.选项值是写入文件的目录。
This option should be used only when mysqldump is run on the same machine as the mysqld server. 仅当mysqldump与mysqld服务器在同一台计算机上运行时,才应使用此选项。Because the server creates 因为服务器在您指定的目录中创建*.txt
files in the directory that you specify, the directory must be writable by the server and the MySQL account that you use must have the FILE
privilege. *.txt
文件,所以该目录必须可由服务器写入,并且您使用的MySQL帐户必须具有FILE
权限。Because mysqldump creates 因为mysqldump在同一目录中创建了*.sql
in the same directory, it must be writable by your system login account.*.sql
,所以它必须可由您的系统登录帐户写入。
By default, the 默认情况下,.txt
data files are formatted using tab characters between column values and a newline at the end of each line. .txt
数据文件使用列值之间的制表符和每行末尾的换行符进行格式化。The format can be specified explicitly using the 可以使用以选项结尾的--fields-
and xxx
--lines-terminated-by
options.--fields-xxx
和--lines
显式指定格式。
Column values are converted to the character set specified by the 列值将转换为由--default-character-set
option.--default-character-set
选项指定的字符集。
This option enables 此选项允许在不同时区的服务器之间转储和重新加载TIMESTAMP
columns to be dumped and reloaded between servers in different time zones. TIMESTAMP
列。mysqldump sets its connection time zone to UTC and adds mysqldump将其连接时区设置为UTC,并将SET TIME_ZONE='+00:00'
to the dump file. SET TIME_ZONE='+00:00'
添加到转储文件中。Without this option, 如果没有此选项,TIMESTAMP
columns 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. TIMESTAMP
列将在源服务器和目标服务器本地的时区中转储和重新加载,如果服务器位于不同的时区,这可能会导致值发生变化。--tz-utc
also protects against changes due to daylight saving time. --tz-utc
is enabled by default. To disable it, use --skip-tz-utc
.--tz-utc
还可以防止夏令时的变化。--tz-utc
默认启用。要禁用它,请使用--skip-tz-utc
。
Write dump output as well-formed XML.将转储输出写入格式良好的XML。
NULL
, 、'NULL'
, and Empty Values和空值: For a column named :对于名column_name
, the NULL
value, an empty string, and the string value 'NULL'
are distinguished from one another in the output generated by this option as follows.为column_name
的列,在该选项生成的输出中,NULL
值、空字符串和字符串值'NULL'
彼此区分如下。
XML | |
---|---|
NULL ( |
|
'' ( |
|
'NULL' ( |
|
The output from the mysql client when run using the 使用--xml
option also follows the preceding rules. (See Section 4.5.1.1, “mysql Client Options”.)--xml
选项运行mysql客户端时的输出也遵循上述规则。(参阅第4.5.1.1节,“mysql客户端选项”。)
XML output from mysqldump includes the XML namespace, as shown here:mysqldump的XML输出包括XML命名空间,如下所示:
shell>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>
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.WHERE
子句从表数据中筛选行。
Dump all tables in all databases. This is the same as using the 转储所有数据库中的所有表。这与使用--databases
option and naming all the databases on the command line.--databases
选项并在命令行上命名所有数据库相同。
See the 有关该选项与--add-drop-database
description for information about an incompatibility of that option with --all-databases
.--all-databases
不兼容的信息,请参阅--add-drop-database
描述。
Prior to MySQL 8.0, the 在MySQL 8.0之前,当使用--routines
and --events
options for mysqldump and mysqlpump were not required to include stored routines and events when using the --all-databases
option: The dump included the mysql
system database, and therefore also the mysql.proc
and mysql.event
tables containing stored routine and event definitions. --all-databases
选项时,mysqldump和mysqlpump的--routines
和--events
选项不需要包括存储的例程和事件:转储包括MySQL系统数据库,因此也包括包含存储例程和事件定义的mysql.proc
和mysql.event
表。As of MySQL 8.0, the 从MySQL 8.0开始,不使用mysql.event
and mysql.proc
tables are not used. mysql.event
和mysql.proc
表。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
and --events
options explicitly.--all-databases
创建的转储中包含存储的例程和事件,请显式使用--routines
和--events
选项。
Dump several databases. Normally, mysqldump treats the first name argument on the command line as a database name and following names as table names. 转储多个数据库。通常,mysqldump将命令行上的第一个name参数视为数据库名称,将后面的名称视为表名称。With this option, it treats all name arguments as database names. 使用此选项,它将所有名称参数视为数据库名称。CREATE DATABASE
and USE
statements are included in the output before each new database.CREATE DATABASE
和USE
语句包含在每个新数据库之前的输出中。
This option may be used to dump the 此选项可用于转储performance_schema
database, which normally is not dumped even with the --all-databases
option. performance_schema
数据库,即使使用--all-databases
选项,通常也不会转储该数据库。(Also use the (也可以使用--skip-lock-tables
option.)--skip-lock-tables
选项。)
See the 有关该选项与--add-drop-database
description for information about an incompatibility of that option with --databases
.--databases
不兼容的信息,请参阅--add-drop-database
描述。
Include Event Scheduler events for the dumped databases in the output. This option requires the 在输出中包含转储数据库的事件计划程序事件。此选项需要这些数据库的EVENT
privileges for those databases.EVENT
权限。
The output generated by using 使用--events
contains CREATE EVENT
statements to create the events.--events
生成的输出包含创建事件的CREATE EVENT
语句。
--ignore-error=
error[,error]...
Ignore the specified errors. 忽略指定的错误。The option value is a list of comma-separated error numbers specifying the errors to ignore during mysqldump execution. 选项值是逗号分隔的错误号列表,指定在mysqldump执行期间要忽略的错误。If the 如果还提供了--force
option is also given to ignore all errors, --force
takes precedence.--force
选项来忽略所有错误,则--force
优先。
--ignore-table=
db_name.tbl_name
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.不要转储给定的表,必须使用数据库和表名指定该表。要忽略多个表,请多次使用此选项。此选项也可用于忽略视图。
Do not write any table row information (that is, do not dump table contents). This is useful if you want to dump only the 不要写入任何表行信息(即不要转储表内容)。如果您只想转储表的CREATE TABLE
statement for the table (for example, to create an empty copy of the table by loading the dump file).CREATE TABLE
语句(例如,通过加载转储文件创建表的空副本),这很有用。
Include stored routines (procedures and functions) for the dumped databases in the output. This option requires the global 在输出中包含转储数据库的存储例程(过程和函数)。此选项需要全局SELECT
privilege.SELECT
权限。
The output generated by using 使用--routines
contains CREATE PROCEDURE
and CREATE FUNCTION
statements to create the routines.--routines
生成的输出包含用于创建例程的CREATE PROCEDURE
和CREATE FUNCTION
语句。
Override the 覆盖--databases
or -B
option. mysqldump regards all name arguments following the option as table names.--databases
或-B
选项。mysqldump将选项后面的所有名称参数视为表名。
Include triggers for each dumped table in the output. This option is enabled by default; disable it with 在输出中包含每个转储表的触发器。默认情况下启用此选项;用--skip-triggers
.--skip-triggers
禁用它。
To be able to dump a table's triggers, you must have the 为了能够转储表的触发器,您必须拥有该表的TRIGGER
privilege for the table.TRIGGER
权限。
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. 允许使用多个触发器。mysqldump转储会按照激活顺序触发,这样当转储文件被重新加载时,触发器也会按照相同的激活顺序创建。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. 但是,如果mysqldump转储文件包含具有相同触发事件和操作时间的表的多个触发器,则尝试将转储文件加载到不支持多个触发器的旧服务器时会发生错误。(For a workaround, see Downgrade Notes; you can convert triggers to be compatible with older servers.)(有关解决方法,请参阅降级注释;您可以将触发器转换为与旧服务器兼容。)
--where='
, where_condition
'-w '
where_condition
'
Dump only rows selected by the given 仅转储由给定WHERE
condition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.WHERE
条件选择的行。如果条件包含空格或其他命令解释器特有的字符,则围绕条件的引号是必需的。
Examples:示例:
--where="user='jimf'" -w"userid>1" -w"userid<1"
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. INSERT
语句)是最耗时的部分。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.InnoDB
和混合用途数据库的MySQL Enterprise backup
。
Performance is also affected by the transactional options, primarily for the dump operation.性能也受到事务选项的影响,主要是转储操作。
Add 将ANALYZE TABLE
statements 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.ANALYZE TABLE
语句添加到输出中,以便在重新加载转储文件时为转储的表生成直方图统计信息。默认情况下,此选项处于禁用状态,因为大型表的直方图生成可能需要很长时间。
For each table, surround the 对于每个表,在INSERT
statements with /*!40000 ALTER TABLE
and tbl_name
DISABLE KEYS */;/*!40000 ALTER TABLE
statements. tbl_name
ENABLE KEYS */;INSERT
语句周围加上/*!40000 ALTER TABLE tbl_name DISABLE KEYS */;
和/*!40000 ALTER TABLE tbl_name ENABLE KEYS */;
语句。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 of 这使得加载转储文件更快,因为索引是在插入所有行后创建的。此选项仅对MyISAM
tables.MyISAM
表的非唯一索引有效。
Write 使用包含多个INSERT
statements using multiple-row syntax that includes several VALUES
lists. VALUES
列表的多行语法编写INSERT
语句。This results in a smaller dump file and speeds up inserts when the file is reloaded.这会导致转储文件变小,并在重新加载文件时加快插入速度。
Write 编写INSERT IGNORE
statements rather than INSERT
statements.INSERT IGNORE
语句而不是INSERT
语句。
The maximum size of the buffer for client/server communication. The default is 24MB, the maximum is 1GB.客户端/服务器通信的最大缓冲区大小。默认值为24MB,最大值为1GB。
The initial size of the buffer for client/server communication. 客户端/服务器通信缓冲区的初始大小。When creating multiple-row 当创建多行INSERT
statements (as with the --extended-insert
or --opt
option), mysqldump creates rows up to --net-buffer-length
bytes long. INSERT
语句时(如使用--extended-insert
或--opt
选项),mysqldump会创建长达--net-buffer-length
字节的行。If you increase this variable, ensure that the MySQL server 如果增加此变量,请确保MySQL服务器net_buffer_length
system variable has a value at least this large.net_buffer_length
系统变量的值至少如此之大。
Enable large tables to be dumped by setting 通过将--max-allowed-packet
to its maximum value and network read and write timeouts to a large value. --max-allowed-packet
设置为最大值,并将网络读写超时设置为较大值,来启用大型表的转储。This option is enabled by default. To disable it, use 默认情况下启用此选项。要禁用它,请使用--skip-network-timeout
.--skip-network-timeout
。
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
. --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.它提供了一个快速的转储操作,并生成了一个可以快速重新加载到MySQL服务器中的转储文件。
Because the 因为默认情况下启用了--opt
option is enabled by default, you only specify its converse, the --skip-opt
to turn off several default settings. --opt
选项,所以您只需指定其相反的--skip-opt
即可关闭几个默认设置。See the discussion of 有关选择性启用或禁用受mysqldump
option groups for information about selectively enabling or disabling a subset of the options affected by --opt
.--opt
影响的选项子集的信息,请参阅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.此选项对于转储大型表非常有用。它强制mysqldump一次从服务器检索一个表的行,而不是检索整个行集并在写入之前将其缓冲在内存中。
See the description for the 请参阅--opt
option.--opt
选项的说明。
The following options trade off the performance of the dump operation, against the reliability and consistency of the exported data.以下选项权衡了转储操作的性能与导出数据的可靠性和一致性。
Surround each table dump with 用LOCK TABLES
and UNLOCK TABLES
statements. LOCK TABLES
和UNLOCK TABLES
语句包围每个表转储。This results in faster inserts when the dump file is reloaded. See Section 8.2.5.1, “Optimizing INSERT Statements”.这使得在重新加载转储文件时插入速度更快。请参阅第8.2.5.1节,“优化INSERT语句”。
Flush the MySQL server log files before starting the dump. This option requires the 在开始转储之前,刷新MySQL服务器日志文件。此选项需要RELOAD
privilege. RELOAD
权限。If you use this option in combination with the 如果将此选项与--all-databases
option, the logs are flushed for each database dumped. --all-databases
选项结合使用,则会为每个转储的数据库刷新日志。The exception is when using 例外情况是使用--lock-all-tables
, --master-data
, or --single-transaction
: In this case, the logs are flushed only once, corresponding to the moment that all tables are locked by FLUSH TABLES WITH READ LOCK
. --lock-all-tables
、--master-data
或--single-transaction
时:在这种情况下,日志只刷新一次,对应于所有表都被FLUSH TABLES WITH READ LOCK
锁定的时刻。If you want your dump and the log flush to happen at exactly the same moment, you should use 如果你想让转储和日志刷新在同一时刻发生,你应该将--flush-logs
together with --lock-all-tables
, --master-data
, or --single-transaction
.--flush-logs
与--lock-all-tables
、--master-data
或--single-transaction
一起使用。
Add a 在转储mysql数据库后,将FLUSH PRIVILEGES
statement to the dump output after dumping the mysql
database. FLUSH PRIVILES
语句添加到转储输出中。This option should be used any time the dump contains the 此选项应在转储包含mysql数据库和任何其他依赖mysql数据库中的数据进行正确还原的数据库时使用。mysql
database and any other database that depends on the data in the mysql
database for proper restoration.
Because the dump file contains a 因为转储文件包含FLUSH PRIVILEGES
statement, reloading the file requires privileges sufficient to execute that statement.FLUSH PRIVILES
语句,所以重新加载文件需要足够的权限来执行该语句。
For upgrades to MySQL 5.7 or higher from older versions, do not use 对于从旧版本升级到MySQL 5.7或更高版本,请不要使用--flush-privileges
. For upgrade instructions in this case, see Section 2.11.4, “Changes in MySQL 8.0”.--flush-privileges
。有关这种情况下的升级说明,请参阅第2.11.4节,“MySQL 8.0中的更改”。
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-transaction
and --lock-tables
.--single-transaction
和--lock-tables
。
For each dumped database, lock all tables to be dumped before dumping them. 对于每个转储的数据库,在转储之前锁定所有要转储的表。The tables are locked with 这些表用READ LOCAL
to permit concurrent inserts in the case of MyISAM
tables. READ LOCAL
锁定,以便在MyISAM
表的情况下允许并发插入。For transactional tables such as 对于InnoDB
, --single-transaction
is a much better option than --lock-tables
because it does not need to lock the tables at all.InnoDB
这样的事务表,--single-transaction
比--lock-tables
要好得多,因为它根本不需要锁表。
Because 因为--lock-tables
locks tables for each database separately, this option does not guarantee that the tables in the dump file are logically consistent between databases. --lock-tables
分别锁定每个数据库的表,所以此选项不能保证转储文件中的表在数据库之间逻辑一致。Tables in different databases may be dumped in completely different states.不同数据库中的表可能以完全不同的状态转储。
Some options, such as 一些选项,如--opt
, automatically enable --lock-tables
. If you want to override this, use --skip-lock-tables
at the end of the option list.--opt
,会自动启用--lock-tables
。如果要覆盖此项,请在选项列表末尾使用--skip-lock-tables
。
Enclose the 将每个转储表的INSERT
statements for each dumped table within SET autocommit = 0
and COMMIT
statements.INSERT
语句包含在SET autocommit=0
和COMMIT
语句中。
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 a 转储每个表的行,按其主键排序,或按其第一个唯一索引排序(如果存在这样的索引)。当转储MyISAM
table to be loaded into an InnoDB
table, but makes the dump operation take considerably longer.MyISAM
表以加载到InnoDB
表中时,这很有用,但会使转储操作花费更长的时间。
--shared-memory-base-name=
name
On Windows, the shared-memory name to use for connections made using shared memory to a local server. The default value is 在Windows上,用于使用共享内存连接到本地服务器的共享内存名称。默认值为MYSQL
. The shared-memory name is case-sensitive.MYSQL
。共享内存名称区分大小写。
This option applies only if the server was started with the 此选项仅适用于服务器启动时启用了shared_memory
system variable enabled to support shared-memory connections.shared_memory
系统变量以支持共享内存连接的情况。
This option sets the transaction isolation mode to 此选项将事务隔离模式设置为REPEATABLE READ
and sends a START TRANSACTION
SQL statement to the server before dumping data. REPEATABLE READ
,并在转储数据之前向服务器发送START TRANSACTION
SQL语句。It is useful only with transactional tables such as 它只对事务表(如InnoDB
, because then it dumps the consistent state of the database at the time when START TRANSACTION
was issued without blocking any applications.InnoDB
)有用,因为这样它会在发出START TRANSACTION
时转储数据库的一致状态,而不会阻塞任何应用程序。
When using this option, you should keep in mind that only 使用此选项时,您应该记住,只有InnoDB
tables are dumped in a consistent state. For example, any MyISAM
or MEMORY
tables dumped while using this option may still change state.InnoDB
表才会以一致的状态转储。例如,使用此选项时转储的任何MyISAM
或MEMORY
表仍可能更改状态。
While a 在进行--single-transaction
dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates), no other connection should use the following statements: ALTER TABLE
, CREATE TABLE
, DROP TABLE
, RENAME TABLE
, TRUNCATE TABLE
. --single-transaction
转储时,为了确保转储文件有效(表内容和二进制日志坐标正确),其他连接不应使用以下语句:ALTER TABLE
、CREATE TABLE
、DROP TABLE
、RENAME TABLE
、TRUNCATE TABLE
。A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the 一致性读取不是与这些语句隔离的,因此在要转储的表上使用它们可能会导致mysqldump执行的SELECT
that is performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail.SELECT
检索表内容以获取不正确的内容或失败。
The --single-transaction
option and the --lock-tables
option are mutually exclusive because LOCK TABLES
causes any pending transactions to be committed implicitly.--single-transaction
选项和--lock-tables
选项是互斥的,因为LOCK TABLES
会隐式提交任何挂起的事务。
To dump large tables, combine the 要转储大型表,请将--single-transaction
option with the --quick
option.--single-transaction
选项与--quick
选项组合使用。
The --opt
option turns on several settings that work together to perform a fast dump operation. --opt
选项启用多个设置,这些设置协同工作以执行快速转储操作。All of these settings are on by default, because 默认情况下,所有这些设置都是打开的,因为默认情况下--opt
is on by default. Thus you rarely if ever specify --opt
. --opt
是打开的。因此,您很少指定--opt
。Instead, you can turn these settings off as a group by specifying 相反,您可以通过指定--skip-opt
, the optionally re-enable certain settings by specifying the associated options later on the command line.--skip-opt
将这些设置作为一个组关闭,也可以通过稍后在命令行上指定相关选项来重新启用某些设置。
The --compact
option turns off several settings that control whether optional statements and comments appear in the output. --compact
选项关闭了几个设置,这些设置控制可选语句和注释是否显示在输出中。Again, you can follow this option with other options that re-enable certain settings, or turn all the settings on by using the 同样,您可以在这个选项之后使用其他选项重新启用某些设置,或者使用--skip-compact
form.--skip-compact
表单打开所有设置。
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.--disable-keys
--lock-tables
--skip-opt
不会达到预期效果;这与跳过opt本身是一样的。
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 is also very useful for populating databases by copying data from one MySQL server to another:mysqldump对于通过将数据从一个MySQL服务器复制到另一个服务器来填充数据库也非常有用:
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
To dump all databases, use the 要转储所有数据库,请使用--all-databases
option:--all-databases
选项:
mysqldump --all-databases > all_databases.sql
For 对于InnoDB
tables, mysqldump provides a way of making an online backup:InnoDB
表,mysqldump提供了一种在线备份的方法:
mysqldump --all-databases --master-data --single-transaction > all_databases.sql
This backup acquires a global read lock on all tables (using 此备份在转储开始时获取所有表的全局读取锁(使用FLUSH TABLES WITH READ LOCK
) at the beginning of the dump. FLUSH TABLES WITH READ LOCK
)。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.FLUSH
语句时正在运行长更新语句,MySQL服务器可能会暂停,直到这些语句完成。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.如果MySQL服务器接收到的更新语句很短(就执行时间而言),即使有很多更新,初始锁定期也不应该很明显。
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 5.4.4, “The Binary Log”) or at least know the binary log coordinates to which the dump corresponds:对于时间点恢复(也称为“前滚”,当您需要还原旧备份并重放自该备份以来发生的更改时),旋转二进制日志(参阅第5.4.4节,“二进制日志”)或至少知道转储对应的二进制日志坐标通常很有用:
mysqldump --all-databases --master-data=2 > all_databases.sql
Or:或者:
mysqldump --all-databases --flush-logs --master-data=2 > all_databases.sql
The --master-data
and --single-transaction
options can be used simultaneously, 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.--master-data
和--single-transaction
选项可以同时使用,这提供了一种方便的方法,可以在使用InnoDB
存储引擎存储表的情况下,在时间点恢复之前进行在线备份。
For more information on making backups, see Section 7.2, “Database Backup Methods”, and Section 7.3, “Example Backup and Recovery Strategy”.有关备份的更多信息,请参阅第7.2节,“数据库备份方法”和第7.3节,“备份和恢复策略示例”。
To select the effect of 要选择--opt
except for some features, use the --skip
option for each feature. --opt
的效果(某些功能除外),请为每个功能使用--skip
选项。To disable extended inserts and memory buffering, use 要禁用扩展插入和内存缓冲,请使用--opt
--skip-extended-insert
--skip-quick
. --opt
--skip-extended-insert
--skip-quick
。(Actually, (实际上,--skip-extended-insert
--skip-quick
is sufficient because --opt
is on by default.)--skip-extended-insert
--skip-quick
就足够了,因为默认情况下--opt
是打开的。)
To reverse 要反转--opt
for all features except index disabling and table locking, use --skip-opt
--disable-keys
--lock-tables
.--opt
除索引禁用和表锁定之外的所有功能,请使用--skip-opt
--disable-keys
--lock-tables
。
mysqldump does not dump the 默认情况下,mysqldump不会转储performance_schema
or sys
schema by default. performance_schema
或sys
模式。To dump any of these, name them explicitly on the command line. You can also name them with the 要转储其中任何一个,请在命令行上明确命名它们。您还可以使用--databases
option. --databases
选项来命名它们。For 对于performance_schema
, also use the --skip-lock-tables
option.performance_schema
,还可以使用--skip-lock-tables
选项。
mysqldump does not dump the mysqldump不转储INFORMATION_SCHEMA
schema.INFORMATION_SCHEMA
架构。
mysqldump does not dump mysqldump不会转储InnoDB
CREATE TABLESPACE
statements.InnoDB CREATE TABLESPACE
语句。
mysqldump does not dump the NDB Cluster mysqldump不会转储NDB群集ndbinfo
information database.ndbinfo
信息数据库。
mysqldump includes statements to recreate the mysqldump包含用于为mysql数据库的转储重新创建general_log
and slow_query_log
tables for dumps of the mysql
database. Log table contents are not dumped.general_log
和slow_query_log
表的语句。日志表内容不会被转储。
If you encounter problems backing up views due to insufficient privileges, see Section 25.9, “Restrictions on Views” for a workaround.如果由于权限不足而在备份视图时遇到问题,请参阅第25.9节,“视图限制”以获取解决方法。