This section discusses a procedure for performing backups that enables you to recover data after several types of crashes:本节讨论了执行备份的过程,该过程使您能够在几种类型的崩溃后恢复数据:
Operating system crash操作系统崩溃
Power failure电源故障
File system crash文件系统崩溃
Hardware problem (hard drive, motherboard, and so forth)硬件问题(硬盘、主板等)
The example commands do not include options such as 示例命令不包括mysqldump和mysql客户端程序的--user
and --password
for the mysqldump and mysql client programs. --user
和--password
等选项。You should include such options as necessary to enable client programs to connect to the MySQL server.您应该包含必要的选项,以使客户端程序能够连接到MySQL服务器。
Assume that data is stored in the 假设数据存储在InnoDB
storage engine, which has support for transactions and automatic crash recovery. Assume also that the MySQL server is under load at the time of the crash. If it were not, no recovery would ever be needed.InnoDB
存储引擎中,该引擎支持事务和自动崩溃恢复。还假设MySQL服务器在崩溃时负载不足。如果没有,就永远不需要复苏。
For cases of operating system crashes or power failures, we can assume that MySQL's disk data is available after a restart. 对于操作系统崩溃或电源故障的情况,我们可以假设MySQL的磁盘数据在重启后可用。The 由于崩溃,InnoDB
data files might not contain consistent data due to the crash, but InnoDB
reads its logs and finds in them the list of pending committed and noncommitted transactions that have not been flushed to the data files. InnoDB
数据文件可能不包含一致的数据,但InnoDB
读取其日志,并在其中找到尚未刷新到数据文件的未决已提交和未提交事务的列表。InnoDB
automatically rolls back those transactions that were not committed, and flushes to its data files those that were committed. InnoDB
会自动回滚未提交的事务,并将已提交的事务刷新到其数据文件中。Information about this recovery process is conveyed to the user through the MySQL error log. The following is an example log excerpt:有关此恢复过程的信息通过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
For the cases of file system crashes or hardware problems, we can assume that the MySQL disk data is not available after a restart. 对于文件系统崩溃或硬件问题的情况,我们可以假设MySQL磁盘数据在重启后不可用。This means that MySQL fails to start successfully because some blocks of disk data are no longer readable. In this case, it is necessary to reformat the disk, install a new one, or otherwise correct the underlying problem. 这意味着MySQL无法成功启动,因为某些磁盘数据块不再可读。在这种情况下,有必要重新格式化磁盘、安装新磁盘或以其他方式纠正潜在问题。Then it is necessary to recover our MySQL data from backups, which means that backups must already have been made. To make sure that is the case, design and implement a backup policy.然后,有必要从备份中恢复MySQL数据,这意味着必须已经进行了备份。为了确保这一点,设计并实施一个备份策略。