Documentation Home
MySQL 8.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 294.0Kb
Man Pages (Zip) - 409.0Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb
Excerpts from this Manual

MySQL 8.3 Reference Manual  /  Backup and Recovery  /  Example Backup and Recovery Strategy

9.3 示例备份和恢复策略

本节讨论了一个备份过程,以便在多种崩溃情况下恢复数据:

  • 操作系统崩溃

  • 电源故障

  • 文件系统崩溃

  • 硬件问题(硬盘、主板等)

示例命令不包括选项,如--user--password,用于mysqldumpmysql客户端程序。您应该根据需要包含这些选项,以便客户端程序连接到 MySQL 服务器。

假设数据存储在 InnoDB 存储引擎中,该引擎支持事务和自动崩溃恢复。假设 MySQL 服务器在崩溃时处于负载状态。如果不是这样,那么恢复将永远不需要。

对于操作系统崩溃或电源故障的情况,我们可以假设 MySQL 的磁盘数据在重新启动后可用。InnoDB 数据文件可能不包含一致的数据,因为崩溃,但 InnoDB 会从日志中读取未提交的事务列表,并回滚未提交的事务,刷新已提交的事务到数据文件中。关于这个恢复过程的信息将通过 MySQL 错误日志传递给用户。以下是一个示例日志摘录:

InnoDB: Database was not shut down normally.
InnoDB: Starting recovery from log files...
InnoDB: Starting log scan based on checkpoint at
InnoDB: log sequence number 0 13674004
InnoDB: Doing recovery: scanned up to log sequence number 0 13739520
InnoDB: Doing recovery: scanned up to log sequence number 0 13805056
InnoDB: Doing recovery: scanned up to log sequence number 0 13870592
InnoDB: Doing recovery: scanned up to log sequence number 0 13936128
...
InnoDB: Doing recovery: scanned up to log sequence number 0 20555264
InnoDB: Doing recovery: scanned up to log sequence number 0 20620800
InnoDB: Doing recovery: scanned up to log sequence number 0 20664692
InnoDB: 1 uncommitted transaction(s) which must be rolled back
InnoDB: Starting rollback of uncommitted transactions
InnoDB: Rolling back trx no 16745
InnoDB: Rolling back of trx no 16745 completed
InnoDB: Rollback of uncommitted transactions completed
InnoDB: Starting an apply batch of log records to the database...
InnoDB: Apply batch completed
InnoDB: Started
mysqld: ready for connections

对于文件系统崩溃或硬件问题的情况,我们可以假设 MySQL 的磁盘数据在重新启动后不可用。这意味着 MySQL 无法成功启动,因为一些磁盘数据块不可读。在这种情况下,需要重新格式化磁盘,安装新磁盘,或者解决基础问题。然后,需要从备份中恢复 MySQL 数据,这意味着备份必须已经制作好了。为了确保这是可能的,需要设计和实施备份策略。