文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 74%

17.20.3 强制 InnoDB 恢复17.20.3 Forcing InnoDB Recovery

要调查数据库页损坏,你可以使用 SELECT ... INTO OUTFILE 从数据库导出你的表。通常,通过这种方式获得的大多数数据都是完整的。严重的损坏可能会导致 SELECT * FROM tbl_name 语句或 InnoDB 后台操作意外退出或断言,甚至可能导致 InnoDB 前滚恢复崩溃。在这种情况下,你可以使用 innodb_force_recovery 选项来强制 InnoDB 存储引擎启动,同时阻止后台操作运行,以便你可以导出表。例如,你可以在重启服务器前,将以下行添加到选项文件的 [mysqld] 部分:To investigate database page corruption, you might dump your tables from the database with SELECT ... INTO OUTFILE. Usually, most of the data obtained in this way is intact. Serious corruption might cause SELECT * FROM tbl_name statements or InnoDB background operations to unexpectedly exit or assert, or even cause InnoDB roll-forward recovery to crash. In such cases, you can use the innodb_force_recovery option to force the InnoDB storage engine to start up while preventing background operations from running, so that you can dump your tables. For example, you can add the following line to the [mysqld] section of your option file before restarting the server:

[mysqld]
innodb_force_recovery = 1

有关使用选项文件的信息,请参见第 6.2.2.2 节,“使用选项文件”。For information about using option files, see Section 6.2.2.2, “Using Option Files”.

Warning

仅在紧急情况下将 innodb_force_recovery 设置为大于 0 的值,以便您可以启动 InnoDB 并转储您的表。在此之前,请确保您已备份数据库,以防需要重新创建它。值为 4 或更高可能会永久损坏数据文件。只有在您在数据库的单独物理副本上成功测试该设置后,才在生产服务器实例上使用值为 4 或更高的 innodb_force_recovery 设置。在强制 InnoDB 恢复时,应始终从 innodb_force_recovery=1 开始,并仅在必要时逐步增加值。Only set innodb_force_recovery to a value greater than 0 in an emergency situation, so that you can start InnoDB and dump your tables. Before doing so, ensure that you have a backup copy of your database in case you need to recreate it. Values of 4 or greater can permanently corrupt data files. Only use an innodb_force_recovery setting of 4 or greater on a production server instance after you have successfully tested the setting on a separate physical copy of your database. When forcing InnoDB recovery, you should always start with innodb_force_recovery=1 and only increase the value incrementally, as necessary.

innodb_force_recovery 默认值为 0(正常启动,不进行强制恢复)。innodb_force_recovery 可接受的非零值为 1 到 6。较大的值包含较小值的功能。例如,值为 3 包含值 1 和 2 的所有功能。innodb_force_recovery is 0 by default (normal startup without forced recovery). The permissible nonzero values for innodb_force_recovery are 1 to 6. A larger value includes the functionality of lesser values. For example, a value of 3 includes all of the functionality of values 1 and 2.

如果你能够在 innodb_force_recovery 值为 3 或以下的情况下导出你的表,那么你相对安全,只会丢失一些损坏的单个页面上的数据。值为 4 或更高被认为是危险的,因为数据文件可能会被永久损坏。值为 6 被认为是极端的,因为数据库页面会处于过时状态,这反过来可能会导致 B 树 和其他数据库结构中出现更多的损坏。If you are able to dump your tables with an innodb_force_recovery value of 3 or less, then you are relatively safe that only some data on corrupt individual pages is lost. A value of 4 or greater is considered dangerous because data files can be permanently corrupted. A value of 6 is considered drastic because database pages are left in an obsolete state, which in turn may introduce more corruption into B-trees and other database structures.

作为一种安全措施,当 innodb_force_recovery 大于 0 时,InnoDB 会阻止 INSERT、UPDATE 或 DELETE 操作。innodb_force_recovery 设置为 4 或更高将使 InnoDB 进入只读模式。As a safety measure, InnoDB prevents INSERT, UPDATE, or DELETE operations when innodb_force_recovery is greater than 0. An innodb_force_recovery setting of 4 or greater places InnoDB in read-only mode.

  • 1 (SRV_FORCE_IGNORE_CORRUPT)

    即使服务器检测到损坏的页面也让服务器继续运行。尝试让SELECT * FROM tbl_name跳过损坏的索引记录和页面,这有助于导出表。Lets the server run even if it detects a corrupt page. Tries to make SELECT * FROM tbl_name jump over corrupt index records and pages, which helps in dumping tables.

  • 2 (SRV_FORCE_NO_BACKGROUND)

    防止主线程和任何清理线程运行。如果在清理操作过程中发生意外退出,此恢复值可以防止它。Prevents the master thread and any purge threads from running. If an unexpected exit would occur during the purge operation, this recovery value prevents it.

  • 3 (SRV_FORCE_NO_TRX_UNDO)

    在 崩溃恢复 后不执行事务 回滚。Does not run transaction rollbacks after crash recovery.

  • 4 (SRV_FORCE_NO_IBUF_MERGE)

    防止 插入缓冲 合并操作。如果这些操作可能导致崩溃,则不执行它们。不会计算表的 统计信息。此值可能会永久损坏数据文件。使用此值后,准备删除并重新创建所有二级索引。将 InnoDB 设置为只读。Prevents insert buffer merge operations. If they would cause a crash, does not do them. Does not calculate table statistics. This value can permanently corrupt data files. After using this value, be prepared to drop and recreate all secondary indexes. Sets InnoDB to read-only.

  • 5 (SRV_FORCE_NO_UNDO_LOG_SCAN)

    在启动数据库时不查看回滚日志:InnoDB 即使对未完成的事务也视为已提交。此值可能永久损坏数据文件。将 InnoDB 设置为只读。Does not look at undo logs when starting the database: InnoDB treats even incomplete transactions as committed. This value can permanently corrupt data files. Sets InnoDB to read-only.

  • 6 (SRV_FORCE_NO_LOG_REDO)

    在恢复过程中不执行与重做日志相关的重做操作。此值可能永久损坏数据文件。使数据库页面处于过时状态,这可能进一步导致 B 树和其他数据库结构出现更多损坏。将 InnoDB 设置为只读。Does not do the redo log roll-forward in connection with recovery. This value can permanently corrupt data files. Leaves database pages in an obsolete state, which in turn may introduce more corruption into B-trees and other database structures. Sets InnoDB to read-only.

你可以从表中 SELECT 出数据。 当 innodb_force_recovery 值为 3 或更低时,你可以 DROP 或 CREATE 表。 使用大于 3 的 innodb_force_recovery 值也支持 DROP TABLE。 当 innodb_force_recovery 值大于 4 时,不允许 DROP TABLE。You can SELECT from tables to dump them. With an innodb_force_recovery value of 3 or less you can DROP or CREATE tables. DROP TABLE is also supported with an innodb_force_recovery value greater than 3. DROP TABLE is not permitted with an innodb_force_recovery value greater than 4.

如果你知道某个表在回滚时导致意外退出,你可以删除它。如果遇到因失败的大量导入或 ALTER TABLE 引起的失控回滚,你可以终止 mysqld 进程,并将 innodb_force_recovery 设置为 3,以在不进行回滚的情况下启动数据库,然后 DROP 导致失控回滚的表。If you know that a given table is causing an unexpected exit on rollback, you can drop it. If you encounter a runaway rollback caused by a failing mass import or ALTER TABLE, you can kill the mysqld process and set innodb_force_recovery to 3 to bring the database up without the rollback, and then DROP the table that is causing the runaway rollback.

如果表数据中的损坏阻止你导出整个表的内容,带有 ORDER BY primary_key DESC 子句的查询可能能够导出损坏部分之后的表数据。If corruption within the table data prevents you from dumping the entire table contents, a query with an ORDER BY primary_key DESC clause might be able to dump the portion of the table after the corrupted part.

如果需要较高的 innodb_force_recovery 值来启动 InnoDB,可能存在损坏的数据结构,这可能导致复杂查询(包含 WHERE、ORDER BY 或其他子句的查询)失败。在这种情况下,你可能只能运行基本的 SELECT * FROM t 查询。If a high innodb_force_recovery value is required to start InnoDB, there may be corrupted data structures that could cause complex queries (queries containing WHERE, ORDER BY, or other clauses) to fail. In this case, you may only be able to run basic SELECT * FROM t queries.