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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 6 个 MySQL 程序 / 6.6 管理和实用程序 / 6.6.2 innochecksum — 离线 InnoDB 文件校验和实用程序
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 84%

6.6.2 innochecksum — 离线 InnoDB 文件校验和工具6.6.2 innochecksum — Offline InnoDB File Checksum Utility

innochecksum 打印 InnoDB 文件的校验和。该工具读取 InnoDB 表空间文件,计算每个页面的校验和,将计算出的校验和与存储的校验和进行比较,并报告不匹配的情况,这表示页面损坏。它最初是为在断电后加快验证表空间文件完整性而开发的,但也可在文件复制后使用。由于校验和不匹配会导致 InnoDB 故意关闭正在运行的服务器,因此使用此工具可能比等待生产服务器遇到损坏页面更可取。innochecksum prints checksums for InnoDB files. 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. 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.

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

如果发现校验和不匹配,请从备份中还原表空间,或者启动服务器并尝试使用mysqldump对表空间中的表进行备份。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.

像这样调用innochecksum:Invoke innochecksum like this:

innochecksum [options] file_name

innochecksum 选项innochecksum Options

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

  • --help, -?

    命令行格式Command-Line Format --help--help
    类型Type 布尔Boolean
    默认值Default Value falsefalse

    显示命令行帮助。示例用法:Displays command line help. Example usage:

    innochecksum --help
    
  • --info, -I

    命令行格式Command-Line Format --info
    类型Type 布尔Boolean
    默认值Default Value falsefalse

    与 --help 同义。显示命令行帮助。使用示例:Synonym for --help. Displays command line help. Example usage:

    innochecksum --info
    
  • --version, -V

    命令行格式Command-Line Format --version
    类型Type 布尔Boolean
    默认值Default Value falsefalse

    显示版本信息。示例用法:Displays version information. Example usage:

    innochecksum --version
    
  • --verbose, -v

    命令行格式Command-Line Format --verbose--verbose
    类型Type 布尔Boolean
    默认值Default Value falsefalse

    详细模式;每五秒向日志文件打印一次进度指示。为了打印进度指示,必须使用--log option指定日志文件。要开启verbose模式,请运行:Verbose mode; prints a progress indicator to the log file every five seconds. In order for the progress indicator to be printed, the log file must be specified using the --log option. To turn on verbose mode, run:

    innochecksum --verbose
    

    要关闭详细模式,请运行:To turn off verbose mode, run:

    innochecksum --verbose=FALSE
    

    --verbose 选项和 --log 选项可以同时指定。例如:The --verbose option and --log option can be specified at the same time. For example:

    innochecksum --verbose --log=/var/lib/mysql/test/logtest.txt
    

    要在日志文件中找到进度指示器信息,您可以执行以下搜索:To locate the progress indicator information in the log file, you can perform the following search:

    cat ./logtest.txt | grep -i "okay"
    

    日志文件中的进度指示器信息类似于以下内容:The progress indicator information in the log file appears similar to the following:

    page 1663 okay: 2.863% done
    page 8447 okay: 14.537% done
    page 13695 okay: 23.568% done
    page 18815 okay: 32.379% done
    page 23039 okay: 39.648% done
    page 28351 okay: 48.789% done
    page 33023 okay: 56.828% done
    page 37951 okay: 65.308% done
    page 44095 okay: 75.881% done
    page 49407 okay: 85.022% done
    page 54463 okay: 93.722% done
    ...
    
  • --count, -c

    命令行格式Command-Line Format --count
    类型Type 基础名称Base name
    默认值Default Value truetrue

    打印文件中的页数并退出。使用示例:Print a count of the number of pages in the file and exit. Example usage:

    innochecksum --count ../data/test/tab1.ibd
    
  • --start-page=num, -s num --start-page=num, -s num

    命令行格式Command-Line Format --start-page=#
    类型Type 数字Numeric
    默认值Default Value 0

    从这个页码开始。示例用法:Start at this page number. Example usage:

    innochecksum --start-page=600 ../data/test/tab1.ibd
    

    或:or:

    innochecksum -s 600 ../data/test/tab1.ibd
    
  • --end-page=num, -e num --end-page=num, -e num

    命令行格式Command-Line Format --end-page=#
    类型Type 数字Numeric
    默认值Default Value 0
    最小值Minimum Value 0
    最大值Maximum Value 18446744073709551615

    在此页码结束。示例用法:End at this page number. Example usage:

    innochecksum --end-page=700 ../data/test/tab1.ibd
    

    或:or:

    innochecksum --p 700 ../data/test/tab1.ibd
    
  • --page=num, -p num

    命令行格式Command-Line Format --page=#
    类型Type 整数Integer
    默认值Default Value 0

    仅检查此页码。使用示例:Check only this page number. Example usage:

    innochecksum --page=701 ../data/test/tab1.ibd
    
  • --strict-check, -C

    命令行格式Command-Line Format --strict-check=algorithm
    类型Type 枚举Enumeration
    默认值Default Value crc32
    有效值Valid Values

    innodb

    crc32

    nonenone

    指定严格的校验和算法。选项包括 innodb、crc32 和 none。Specify a strict checksum algorithm. Options include innodb, crc32, and none.

    在此示例中,指定了 innodb 校验和算法:In this example, the innodb checksum algorithm is specified:

    innochecksum --strict-check=innodb ../data/test/tab1.ibd
    

    在此示例中,指定了 crc32 校验和算法:In this example, the crc32 checksum algorithm is specified:

    innochecksum -C crc32 ../data/test/tab1.ibd
    

    适用以下条件:The following conditions apply:

    • 如果您没有指定 --strict-check 选项,innochecksum 会验证 innodb、crc32 和 none。If you do not specify the --strict-check option, innochecksum validates against innodb, crc32 and none.

    • 如果您指定 none 选项,则只允许 none 生成的校验和。If you specify the none option, only checksums generated by none are allowed.

    • 如果您指定 innodb 选项,则只允许 innodb 生成的校验和。If you specify the innodb option, only checksums generated by innodb are allowed.

    • 如果您指定 crc32 选项,则只允许 crc32 生成的校验和。If you specify the crc32 option, only checksums generated by crc32 are allowed.

  • --no-check, -n

    命令行格式Command-Line Format --no-check
    类型Type 布尔Boolean
    默认值Default Value falsefalse

    重写校验和时忽略校验和验证。此选项只能与 innochecksum 的 --write 选项一起使用。如果未指定 --write 选项,innochecksum 将终止。Ignore the checksum verification when rewriting a checksum. This option may only be used with the innochecksum --write option. If the --write option is not specified, innochecksum terminates.

    在此示例中,innodb 校验和被重写以替换无效的校验和:In this example, an innodb checksum is rewritten to replace an invalid checksum:

    innochecksum --no-check --write innodb ../data/test/tab1.ibd
    
  • --allow-mismatches, -a

    命令行格式Command-Line Format --allow-mismatches=#
    类型Type 整数Integer
    默认值Default Value 0
    最小值Minimum Value 0
    最大值Maximum Value 18446744073709551615

    在 innochecksum 终止之前允许的最大校验和不匹配次数。默认设置为 0。如果 --allow-mismatches=N,其中 N>=0,则允许 N 次不匹配,并且 innochecksum 在 N+1 时终止。当 --allow-mismatches 设置为 0 时,innochecksum 会在第一次校验和不匹配时终止。The maximum number of checksum mismatches allowed before innochecksum terminates. The default setting is 0. If --allow-mismatches=N, where N>=0, N mismatches are permitted and innochecksum terminates at N+1. When --allow-mismatches is set to 0, innochecksum terminates on the first checksum mismatch.

    在此示例中,现有的 innodb 校验和被重写以将 --allow-mismatches 设置为 1。In this example, an existing innodb checksum is rewritten to set --allow-mismatches to 1.

    innochecksum --allow-mismatches=1 --write innodb ../data/test/tab1.ibd
    

    当 --allow-mismatches 设置为 1 时,如果在一个有 1000 页的文件中,页面 600 出现不匹配,页面 700 又出现不匹配,则页面 0-599 和 601-699 的校验和会被更新。由于 --allow-mismatches 设置为 1,校验和会容忍第一次不匹配,并在第二次不匹配时终止,使页面 600 和页面 700-999 保持不变。With --allow-mismatches set to 1, if there is a mismatch at page 600 and another at page 700 on a file with 1000 pages, the checksum is updated for pages 0-599 and 601-699. Because --allow-mismatches is set to 1, the checksum tolerates the first mismatch and terminates on the second mismatch, leaving page 600 and pages 700-999 unchanged.

  • --write=name, -w num --write=name, -w num

    命令行格式Command-Line Format --write=algorithm--write=algorithm
    类型Type 枚举Enumeration
    默认值Default Value crc32
    有效值Valid Values

    innodb

    crc32

    nonenone

    重写校验和。重写无效的校验和时,必须将--no-check选项与--write选项一起使用。--no-check选项告诉innochecksum忽略对无效校验和的验证。如果当前校验和有效,则不必指定--no-check选项。Rewrite a checksum. When rewriting an invalid checksum, the --no-check option must be used together with the --write option. The --no-check option tells innochecksum to ignore verification of the invalid checksum. You do not have to specify the --no-check option if the current checksum is valid.

    使用--write选项时,必须指定一个算法。--write选项的可能值为:An algorithm must be specified when using the --write option. Possible values for the --write option are:

    • innodb:使用InnoDB的原始算法在软件中计算的校验和。innodb: A checksum calculated in software, using the original algorithm from InnoDB.

    • crc32:使用crc32算法计算的校验和,可能借助硬件加速完成。crc32: A checksum calculated using the crc32 algorithm, possibly done with a hardware assist.

    • none:一个常数值。none: A constant number.

    --write选项会将整个页面重写到磁盘。如果新校验和与现有校验和相同,则不会将新校验和写入磁盘,以最小化 I/O。The --write option rewrites entire pages to disk. If the new checksum is identical to the existing checksum, the new checksum is not written to disk in order to minimize I/O.

    innochecksum 在使用 --write。innochecksum obtains an exclusive lock when the --write option is used.

    在此示例中,crc32 校验和写为 tab1.ibd:In this example, a crc32 checksum is written for tab1.ibd:

    innochecksum -w crc32 ../data/test/tab1.ibd
    

    在此示例中,crc32 校验和被重写为替换无效的 crc32 checksum:In this example, a crc32 checksum is rewritten to replace an invalid crc32 checksum:

    innochecksum --no-check --write crc32 ../data/test/tab1.ibd
    
  • --page-type-summary, -S

    命令行格式Command-Line Format --page-type-summary
    类型Type 布尔Boolean
    默认值Default Value falsefalse

    显示表空间中每种页面类型的数量。例如用法:Display a count of each page type in a tablespace. Example usage:

    innochecksum --page-type-summary ../data/test/tab1.ibd
    

    --page-type-summary 的示例输出:Sample output for --page-type-summary:

    File::../data/test/tab1.ibd
    ================PAGE TYPE SUMMARY==============
    #PAGE_COUNT PAGE_TYPE
    ===============================================
           2        Index page
           0        Undo log page
           1        Inode page
           0        Insert buffer free list page
           2        Freshly allocated page
           1        Insert buffer bitmap
           0        System page
           0        Transaction system page
           1        File Space Header
           0        Extent descriptor page
           0        BLOB page
           0        Compressed BLOB page
           0        Other type of page
    ===============================================
    Additional information:
    Undo page type: 0 insert, 0 update, 0 other
    Undo page state: 0 active, 0 cached, 0 to_free, 0 to_purge, 0 prepared, 0 other
    
  • --page-type-dump, -D

    命令行格式Command-Line Format --page-type-dump=name--page-type-dump=name
    类型Type 字符串String
    默认值Default Value [none][none]

    将表空间中每个页面的页面类型信息转储到 stderr 或 stdout。用法示例:Dump the page type information for each page in a tablespace to stderr or stdout. Example usage:

    innochecksum --page-type-dump=/tmp/a.txt ../data/test/tab1.ibd
    
  • --log, -l

    命令行格式Command-Line Format --log=path--log=path
    类型Type 文件名File name
    默认值Default Value [none][none]

    innochecksum 工具的日志输出。必须提供日志文件名。日志输出包含每个表空间页的校验值。对于未压缩的表,还提供 LSN 值。示例用法:Log output for the innochecksum tool. A log file name must be provided. Log output contains checksum values for each tablespace page. For uncompressed tables, LSN values are also provided. Example usage:

    innochecksum --log=/tmp/log.txt ../data/test/tab1.ibd
    

    或:or:

    innochecksum -l /tmp/log.txt ../data/test/tab1.ibd
    
  • - 选项。 - option.

    Specify the - option to read from standard input. If the - option is missing when “从标准输入读取” is expected, innochecksum prints innochecksum usage information indicating that the “-” option was omitted. Example usages:Specify the - option to read from standard input. If the - option is missing when “read from standard in” is expected, innochecksum prints innochecksum usage information indicating that the “-” option was omitted. Example usages:

    cat t1.ibd | innochecksum -
    

    在此示例中,innochecksum 将 crc32 校验和算法写入 a.ibd,而不更改原始的 t1.ibd 文件。In this example, innochecksum writes the crc32 checksum algorithm to a.ibd without changing the original t1.ibd file.

    cat t1.ibd | innochecksum --write=crc32 - > a.ibd
    

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

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

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

innochecksum ./data/test/*.ibd

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

innochecksum ./data/test/t*.ibd

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

innochecksum ./data/*/*.ibd
Note

在多个用户定义的表空间文件上运行innochecksum在 Windows 操作系统上不受支持,因为 Windows 的 shell(如 cmd.exe)不支持通配符模式扩展。在 Windows 系统上,innochecksum 必须对每个用户定义的表空间文件单独运行。例如: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. On Windows systems, innochecksum must be run separately for each user-defined tablespace file. For example:

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

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

默认情况下,系统表空间只有一个 InnoDB 系统表空间文件 (ibdata1),但可以使用 innodb_data_file_path 选项定义多个系统表空间文件。在下面的示例中,使用 innodb_data_file_path 选项定义了三个系统表空间文件:ibdata1、ibdata2 和 ibdata3。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. In the following example, three files for the system tablespace are defined using the innodb_data_file_path option: ibdata1, ibdata2, and ibdata3.

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

这三个文件(ibdata1、ibdata2 和 ibdata3)组成一个逻辑系统表空间。要在形成一个逻辑系统表空间的多个文件上运行 innochecksum,innochecksum 需要使用 - 选项从标准输入读取表空间文件,这相当于将多个文件连接以创建一个单一文件。对于上面提供的示例,可以使用以下 innochecksum 命令:The three files (ibdata1, ibdata2, and ibdata3) form one logical system tablespace. 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. For the example provided above, the following innochecksum command would be used:

cat ibdata* | innochecksum -

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

Note

在同一个表空间上对多个文件运行 innochecksum 在 Windows 操作系统上不受支持,因为 Windows shell(如 cmd.exe)不支持通配符模式展开。在 Windows 系统上,必须对每个系统表空间文件单独运行 innochecksum。例如: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. On Windows systems, innochecksum must be run separately for each system tablespace file. For example:

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