4.6.2 innochecksum — Offline InnoDB File Checksum Utility离线InnoDB文件校验和实用程序

innochecksum prints checksums for InnoDB files. innochecksum打印InnoDB文件的校验和。This tool reads an InnoDB tablespace file, calculates the checksum for each page, compares the calculated checksum to the stored checksum, and reports mismatches, which indicate damaged pages. 此工具读取InnoDB表空间文件,计算每个页面的校验和,将计算的校验和与存储的校验和进行比较,并报告不匹配,这表明页面已损坏。It was originally developed to speed up verifying the integrity of tablespace files after power outages but can also be used after file copies. 它最初是为了在停电后加快验证表空间文件的完整性而开发的,但也可以在文件复制后使用。Because checksum mismatches cause InnoDB to deliberately shut down a running server, it may be preferable to use this tool rather than waiting for an in-production server to encounter the damaged pages.因为校验和不匹配会导致InnoDB故意关闭正在运行的服务器,所以最好使用此工具,而不是等待生产中的服务器遇到损坏的页面。

innochecksum cannot be used on tablespace files that the server already has open. innochecksum不能用于服务器已打开的表空间文件。For such files, you should use CHECK TABLE to check tables within the tablespace. 对于此类文件,您应该使用CHECK TABLE检查表空间中的表。Attempting to run innochecksum on a tablespace that the server already has open results in an Unable to lock file error.尝试在服务器已打开的表空间上运行innochecksum会导致无法锁定文件错误。

If checksum mismatches are found, restore the tablespace from backup or start the server and attempt to use mysqldump to make a backup of the tables within the tablespace.如果发现校验和不匹配,请从备份中还原表空间或启动服务器,并尝试使用mysqldump对表空间中的表进行备份。

Invoke innochecksum like this:像这样调用innocecksum

innochecksum [options] file_name

innochecksum Optionsinnochecksum选项

innochecksum supports the following options. For options that refer to page numbers, the numbers are zero-based.innochecksum支持以下选项。对于涉及页码的选项,这些数字是从零开始的。

Running innochecksum on Multiple User-defined Tablespace Files在多个用户定义的表空间文件上运行innochecksum

The following examples demonstrate how to run innochecksum on multiple user-defined tablespace files (.ibd files).以下示例演示了如何在多个用户定义的表空间文件(.ibd文件)上运行innochecksum

Run innochecksum for all tablespace (.ibd) files in the test database:对“test”数据库中的所有表空间(ibd)文件运行innochecksum

innochecksum ./data/test/*.ibd

Run innochecksum for all tablespace files (.ibd files) that have a file name starting with t:对所有文件名以“t”开头的表空间文件(.ibd文件)运行innochecksum

innochecksum ./data/test/t*.ibd

Run innochecksum for all tablespace files (.ibd files) in the data directory:对数据目录中的所有表空间文件(.ibd文件)运行innochecksum

innochecksum ./data/*/*.ibd
Note注意

Running innochecksum on multiple user-defined tablespace files is not supported on Windows operating systems, as Windows shells such as cmd.exe do not support glob pattern expansion. Windows操作系统不支持在多个用户定义的表空间文件上运行innochecksum,因为cmd.exe等Windows shell不支持glob模式扩展。On Windows systems, innochecksum must be run separately for each user-defined tablespace file. For example:在Windows系统上,必须为每个用户定义的表空间文件单独运行innochecksum。例如:

innochecksum.exe t1.ibd
innochecksum.exe t2.ibd
innochecksum.exe t3.ibd

Running innochecksum on Multiple System Tablespace Files在多个系统表空间文件上运行innochecksum

By default, there is only one InnoDB system tablespace file (ibdata1) but multiple files for the system tablespace can be defined using the innodb_data_file_path option. 默认情况下,只有一个InnoDB系统表空间文件(ibdata1),但可以使用innodb_data_file_path选项定义系统表空间的多个文件。In the following example, three files for the system tablespace are defined using the innodb_data_file_path option: ibdata1, ibdata2, and ibdata3.在以下示例中,使用innodb_data_file_path选项定义了系统表空间的三个文件:ibdata1ibdata2ibdata3

./bin/mysqld --no-defaults --innodb-data-file-path="ibdata1:10M;ibdata2:10M;ibdata3:10M:autoextend"

The three files (ibdata1, ibdata2, and ibdata3) form one logical system tablespace. 这三个文件(ibdata1ibdata2ibdata3)形成一个逻辑系统表空间。To run innochecksum on multiple files that form one logical system tablespace, innochecksum requires the - option to read tablespace files in from standard input, which is equivalent to concatenating multiple files to create one single file. 要对形成一个逻辑系统表空间的多个文件运行innochecksuminnochecksum需要-选项从标准输入中读取表空间文件,这相当于连接多个文件以创建一个文件。For the example provided above, the following innochecksum command would be used:对于上面提供的示例,将使用以下innochecksum命令:

cat ibdata* | innochecksum -

Refer to the innochecksum options information for more information about the - option.有关“-”选项的更多信息,请参阅innochecksum选项信息。

Note注意

Running innochecksum on multiple files in the same tablespace is not supported on Windows operating systems, as Windows shells such as cmd.exe do not support glob pattern expansion. Windows操作系统不支持在同一表空间中的多个文件上运行innochecksum,因为cmd.exe等Windows shell不支持glob模式扩展。On Windows systems, innochecksum must be run separately for each system tablespace file. For example:在Windows系统上,必须为每个系统表空间文件单独运行innochecksum。例如:

innochecksum.exe ibdata1
innochecksum.exe ibdata2
innochecksum.exe ibdata3