4.5.4 mysqldump — A Database Backup Program数据库备份程序

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格式的输出。

Tip

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 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. mysqldump至少要求转储表具有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 ALTER DATABASE statements that change the database collation. mysqldump输出可以包含更改数据库排序规则的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权限。

Note注意

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

Performance and Scalability Considerations性能和可扩展性考虑因素

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:对于大规模备份和还原,物理备份更为合适,以可以快速还原的原始格式复制数据文件:

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 --skip-opt option instead of the --opt or --extended-insert option.如果您使用最新版本的mysqldump生成转储以重新加载到非常旧的MySQL服务器中,请使用--skip-opt选项而不是--opt--extended-insert选项。

For additional information about mysqldump, see Section 7.4, “Using mysqldump for Backups”.有关mysqldump的更多信息,请参阅第7.4节,“使用mysqldump进行备份”

Invocation Syntax调用语法

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] --databases db_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

Option Syntax - Alphabetical Summary选项语法-按字母顺序摘要

mysqldump supports the following options, which can be specified on the command line or in the [mysqldump] and [client] groups of an option file. mysqldump支持以下选项,可以在命令行或选项文件的[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选项

Option Name选项名称Description描述Introduced引入版本Deprecated弃用版本
--add-drop-databaseAdd DROP DATABASE statement before each CREATE DATABASE statement在每个CREATE DATABASE语句之前添加DROP DATABASE语句
--add-drop-tableAdd DROP TABLE statement before each CREATE TABLE statement在每个CREATE TABLE语句之前添加DROP TABLE语句
--add-drop-triggerAdd DROP TRIGGER statement before each CREATE TRIGGER statement在每个CREATE TRIGGER语句之前添加DROP TRIGGER语句
--add-locksSurround each table dump with LOCK TABLES and UNLOCK TABLES statementsLOCK TABLESUNLOCK TABLES语句包围每个表转储
--all-databasesDump all tables in all databases转储所有数据库中的所有表
--allow-keywordsAllow creation of column names that are keywords允许创建关键字列名
--apply-slave-statementsInclude STOP SLAVE prior to CHANGE MASTER statement and START SLAVE at end of outputCHANGE MASTER语句之前包含STOP SLAVE,并在输出末尾包含START SLAVE
--bind-addressUse specified network interface to connect to MySQL Server使用指定的网络接口连接MySQL服务器
--character-sets-dirDirectory where character sets are installed安装字符集的目录
--column-statisticsWrite ANALYZE TABLE statements to generate statistics histograms编写ANALYZE TABLE语句以生成统计直方图
--commentsAdd comments to dump file向转储文件添加注释
--compactProduce more compact output生产更紧凑的输出
--compatibleProduce output that is more compatible with other database systems or with older MySQL servers生成与其他数据库系统或旧MySQL服务器更兼容的输出
--complete-insertUse complete INSERT statements that include column names使用包含列名的完整INSERT语句
--compressCompress all information sent between client and server压缩客户端和服务器之间发送的所有信息8.0.18
--compression-algorithmsPermitted compression algorithms for connections to server服务器连接的允许压缩算法8.0.18
--create-optionsInclude all MySQL-specific table options in CREATE TABLE statementsCREATE TABLE语句中包含所有MySQL特定的表选项
--databasesInterpret all name arguments as database names将所有名称参数解释为数据库名称
--debugWrite debugging log写入调试日志
--debug-checkPrint debugging information when program exits程序退出时打印调试信息
--debug-infoPrint debugging information, memory, and CPU statistics when program exits程序退出时打印调试信息、内存和CPU统计信息
--default-authAuthentication plugin to use要使用的身份验证插件
--default-character-setSpecify default character set指定默认字符集
--defaults-extra-fileRead named option file in addition to usual option files除了常规选项文件外,还读取命名选项文件
--defaults-fileRead only named option file只读命名选项文件
--defaults-group-suffixOption group suffix value选项组后缀值
--delete-master-logsOn a master replication server, delete the binary logs after performing the dump operation在主复一致性务器上,执行转储操作后删除二进制日志
--disable-keysFor each table, surround INSERT statements with statements to disable and enable keys对于每个表,用禁用和启用键的语句包围INSERT语句
--dump-dateInclude dump date as "Dump completed on" comment if --comments is given如果给出了注释,请将转储日期作为“转储完成日期”注释
--dump-slaveInclude CHANGE MASTER statement that lists binary log coordinates of slave's master包含CHANGE MASTER语句,该语句列出了从属主机的二进制日志坐标
--enable-cleartext-pluginEnable cleartext authentication plugin启用明文身份验证插件
--eventsDump events from dumped databases从转储的数据库中转储事件
--extended-insertUse multiple-row INSERT syntax使用多行INSERT语法
--fields-enclosed-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA此选项与--tab选项一起使用,其含义与LOAD DATA的相应子句相同
--fields-escaped-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA此选项与--tab选项一起使用,其含义与LOAD DATA的相应子句相同
--fields-optionally-enclosed-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA此选项与--tab选项一起使用,其含义与LOAD DATA的相应子句相同
--fields-terminated-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA此选项与--tab选项一起使用,其含义与LOAD DATA的相应子句相同
--flush-logsFlush MySQL server log files before starting dump在开始转储之前刷新MySQL服务器日志文件
--flush-privilegesEmit a FLUSH PRIVILEGES statement after dumping mysql database转储mysql数据库后发出FLUSH PRIVILES语句
--forceContinue even if an SQL error occurs during a table dump即使在表转储过程中发生SQL错误,也要继续
--get-server-public-keyRequest RSA public key from server从服务器请求RSA公钥
--helpDisplay help message and exit显示帮助消息并退出
--hex-blobDump binary columns using hexadecimal notation使用十六进制表示法转储二进制列
--hostHost on which MySQL server is locatedMySQL服务器所在的主机
--ignore-errorIgnore specified errors忽略指定的错误
--ignore-tableDo not dump given table不要转储给定的表
--include-master-host-portInclude MASTER_HOST/MASTER_PORT options in CHANGE MASTER statement produced with --dump-slave在使用--dump-slave生成的CHANGE MASTER语句中包含MASTER_HOST/MASTER_PORT选项
--insert-ignoreWrite INSERT IGNORE rather than INSERT statementsINSERT IGNORE而不是INSERT语句
--lines-terminated-byThis option is used with the --tab option and has the same meaning as the corresponding clause for LOAD DATA此选项与--tab选项一起使用,其含义与LOAD DATA的相应子句相同
--lock-all-tablesLock all tables across all databases锁定所有数据库中的所有表
--lock-tablesLock all tables before dumping them在倾倒之前锁定所有桌子
--log-errorAppend warnings and errors to named file将警告和错误附加到命名文件
--login-pathRead login path options from .mylogin.cnf.mylogin.cnf读取登录路径选项
--master-dataWrite the binary log file name and position to the output将二进制日志文件名和位置写入输出
--max-allowed-packetMaximum packet length to send to or receive from server发送到服务器或从服务器接收的最大数据包长度
--net-buffer-lengthBuffer size for TCP/IP and socket communicationTCP/IP和套接字通信的缓冲区大小
--network-timeoutIncrease network timeouts to permit larger table dumps增加网络超时以允许更大的表转储
--no-autocommitEnclose the INSERT statements for each dumped table within SET autocommit = 0 and COMMIT statements将每个转储表的INSERT语句包含在SET autocommit=0COMMIT语句中
--no-create-dbDo not write CREATE DATABASE statements不要编写CREATE DATABASE语句
--no-create-infoDo not write CREATE TABLE statements that re-create each dumped table不要编写CREATE TABLE语句来重新创建每个转储的表
--no-dataDo not dump table contents不转储表内容
--no-defaultsRead no option files不读取选项文件
--no-set-namesSame as --skip-set-charset--skip-set-charset相同
--no-tablespacesDo not write any CREATE LOGFILE GROUP or CREATE TABLESPACE statements in output不要在输出中写入任何CREATE LOGFILE GROUPCREATE TABLESPACE语句
--optShorthand for --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的简写
--order-by-primaryDump each table's rows sorted by its primary key, or by its first unique index转储按主键或第一个唯一索引排序的每个表的行
--passwordPassword to use when connecting to server连接到服务器时使用的密码
--pipeConnect to server using named pipe (Windows only)使用命名管道连接到服务器(仅限Windows)
--plugin-dirDirectory where plugins are installed安装插件的目录
--portTCP/IP port number for connection用于连接的TCP/IP端口号
--print-defaultsPrint default options打印默认选项
--protocolTransport protocol to use要使用的传输协议
--quickRetrieve rows for a table from the server a row at a time每次从服务器检索表的行
--quote-namesQuote identifiers within backtick characters引号标识符包含回溯字符
--replaceWrite REPLACE statements rather than INSERT statements编写REPLACE语句而不是INSERT语句
--result-fileDirect output to a given file直接输出到给定文件
--routinesDump stored routines (procedures and functions) from dumped databases从转储的数据库中转储存储的例程(过程和函数)
--server-public-key-pathPath name to file containing RSA public key包含RSA公钥的文件的路径名
--set-charsetAdd SET NAMES default_character_set to outputSET NAMES default_character_set添加到输出中
--set-gtid-purgedWhether to add SET @@GLOBAL.GTID_PURGED to output是否将SET @@GLOBAL.GTID_PURGED添加到输出
--shared-memory-base-nameShared-memory name for shared-memory connections (Windows only)共享内存连接的共享内存名称(仅限Windows)
--show-create-skip-secondary-engineExclude SECONDARY ENGINE clause from CREATE TABLE statementsCREATE TABLE语句中排除SECONDARY ENGINE子句8.0.18
--single-transactionIssue a BEGIN SQL statement before dumping data from server在从服务器转储数据之前发出BEGIN SQL语句
--skip-add-drop-tableDo not add a DROP TABLE statement before each CREATE TABLE statement不要在每个CREATE TABLE语句之前添加DROP TABLE语句
--skip-add-locksDo not add locks不添加锁
--skip-commentsDo not add comments to dump file不向转储文件添加注释
--skip-compactDo not produce more compact output不要产生更紧凑的输出
--skip-disable-keysDo not disable keys不要禁用密钥
--skip-extended-insertTurn off extended-insert关闭扩展插件
--skip-optTurn off options set by --opt关闭--opt设置的选项
--skip-quickDo not retrieve rows for a table from the server a row at a time不要一次一行地从服务器检索表的行
--skip-quote-namesDo not quote identifiers不要引用标识符
--skip-set-charsetDo not write SET NAMES statement不要写SET NAMES语句
--skip-triggersDo not dump triggers不要转储触发器
--skip-tz-utcTurn off tz-utc关闭tz utc
--socketUnix socket file or Windows named pipe to use要使用的Unix套接字文件或Windows命名管道
--ssl-caFile that contains list of trusted SSL Certificate Authorities包含受信任SSL证书颁发机构列表的文件
--ssl-capathDirectory that contains trusted SSL Certificate Authority certificate files包含受信任的SSL证书颁发机构证书文件的目录
--ssl-certFile that contains X.509 certificate包含X.509证书的文件
--ssl-cipherPermissible ciphers for connection encryption连接加密的允许密码
--ssl-crlFile that contains certificate revocation lists包含证书吊销列表的文件
--ssl-crlpathDirectory that contains certificate revocation-list files包含证书吊销列表文件的目录
--ssl-fips-modeWhether to enable FIPS mode on client side是否在客户端启用FIPS模式
--ssl-keyFile that contains X.509 key包含X.509密钥的文件
--ssl-modeDesired security state of connection to server与服务器连接的所需安全状态
--tabProduce tab-separated data files生成以制表符分隔的数据文件
--tablesOverride --databases or -B option覆盖--databases-B选项
--tls-ciphersuitesPermissible TLSv1.3 ciphersuites for encrypted connections加密连接允许的TLSv1.3密码套件8.0.16
--tls-versionPermissible TLS protocols for encrypted connections加密连接的允许TLS协议
--triggersDump triggers for each dumped table每个转储表的转储触发器
--tz-utcAdd SET TIME_ZONE='+00:00' to dump fileSET TIME_ZONE='+00:00'添加到转储文件
--userMySQL user name to use when connecting to server连接到服务器时使用的MySQL用户名
--verboseVerbose mode详细模式
--versionDisplay version information and exit显示版本信息并退出
--whereDump only rows selected by given WHERE condition仅转储由给定WHERE条件选择的行
--xmlProduce XML output生成XML输出
--zstd-compression-levelCompression level for connections to server that use zstd compression使用zstd压缩的服务器连接的压缩级别8.0.18

Connection Options连接选项

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服务器,无论是在同一台机器上还是在远程系统上。

Option-File Options选项文件选项

These options are used to control which option files to read.这些选项用于控制要读取的选项文件。

DDL OptionsDDL选项

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语句来指定在还原转储时要删除和设置哪些内容。

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.以下选项可以打印调试信息,在转储文件中编码调试信息,或者让转储操作继续进行,而不管潜在的问题。

Help Options帮助选项

The following options display information about the mysqldump command itself.以下选项显示有关mysqldump命令本身的信息。

Internationalization Options国际化选项

The following options change how the mysqldump command represents character data with national language settings.以下选项更改mysqldump命令使用国家语言设置表示字符数据的方式。

Replication Options复制选项

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.以下选项适用于在复制源服务器和副本上转储和还原数据。

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.以下选项指定了如何表示整个转储文件或转储文件中的某些类型的数据。它们还控制是否将某些可选信息写入转储文件。

Filtering Options筛选选项

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子句从表数据中筛选行。

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. 以下选项与性能(尤其是还原操作)最为相关。对于大型数据集,还原操作(处理转储文件中的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.性能也受到事务选项的影响,主要是转储操作。

Transactional Options事务选项

The following options trade off the performance of the dump operation, against the reliability and consistency of the exported data.以下选项权衡了转储操作的性能与导出数据的可靠性和一致性。

Option Groups选项组

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本身是一样的。

Examples例子

To make a backup of an entire database:要备份整个数据库,请执行以下操作:

mysqldump db_name > backup-file.sql

To load the dump file back into the server:要将转储文件重新加载到服务器中,请执行以下操作:

mysql db_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 --opt db_name | mysql --host=remote_host -C db_name

You can dump several databases with one command:您可以使用一个命令转储多个数据库:

mysqldump --databases db_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节,“备份和恢复策略示例”

Restrictions限制

mysqldump does not dump the performance_schema or sys schema by default. 默认情况下,mysqldump不会转储performance_schemasys模式。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 INFORMATION_SCHEMA schema.mysqldump不转储INFORMATION_SCHEMA架构。

mysqldump does not dump InnoDB CREATE TABLESPACE statements.mysqldump不会转储InnoDB CREATE TABLESPACE语句。

mysqldump does not dump the NDB Cluster ndbinfo information database.mysqldump不会转储NDB群集ndbinfo信息数据库。

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.mysqldump包含用于为mysql数据库的转储重新创建general_logslow_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节,“视图限制”以获取解决方法。