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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 6 个 MySQL 程序 / 6.6 管理和实用程序 / 6.6.4 myisamchk — MyISAM 表维护实用程序
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 90%

6.6.4 myisamchk — MyISAM 表维护工具6.6.4 myisamchk — MyISAM Table-Maintenance Utility

myisamchk 工具获取有关您的表的信息,或者检查、修复或优化它们。myisamchk 可用于 MyISAM 表(用于存储数据和索引的表,具有 .MYD 和 .MYI 文件)。The myisamchk utility gets information about your database tables or checks, repairs, or optimizes them. myisamchk works with MyISAM tables (tables that have .MYD and .MYI files for storing data and indexes).

你也可以使用 CHECK TABLE 和 REPAIR TABLE 语句来检查和修复 MyISAM 表。参见 第 15.7.3.2 节,“CHECK TABLE 语句”,以及 第 15.7.3.5 节,“REPAIR TABLE 语句”。You can also use the CHECK TABLE and REPAIR TABLE statements to check and repair MyISAM tables. See Section 15.7.3.2, “CHECK TABLE Statement”, and Section 15.7.3.5, “REPAIR TABLE Statement”.

不支持在分区表上使用 myisamchk。The use of myisamchk with partitioned tables is not supported.

Caution

在执行表修复操作之前,最好先备份表;在某些情况下,该操作可能会导致数据丢失。可能的原因包括但不限于文件系统错误。It is best to make a backup of a table before performing a table repair operation; under some circumstances the operation might cause data loss. Possible causes include but are not limited to file system errors.

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

myisamchk [options] tbl_name ...

options 指定你希望 myisamchk 执行的操作。它们在以下各节中有描述。你也可以通过调用 myisamchk --help 来获取选项列表。The options specify what you want myisamchk to do. They are described in the following sections. You can also get a list of options by invoking myisamchk --help.

如果没有选项,myisamchk 将默认检查您的表。要获取更多信息或指示 myisamchk 采取纠正措施,请按下文讨论中描述的方式指定选项。With no options, myisamchk simply checks your table as the default operation. To get more information or to tell myisamchk to take corrective action, specify options as described in the following discussion.

tbl_name 是你想检查或修复的表。如果你在数据库目录之外的地方运行 myisamchk,你必须指定数据库目录的路径,因为 myisamchk 并不知道数据库的位置。实际上,myisamchk 并不关心你操作的文件是否位于数据库目录中。你可以将与表对应的文件复制到其他位置,并在那里执行恢复操作。tbl_name is the database table you want to check or repair. If you run myisamchk somewhere other than in the database directory, you must specify the path to the database directory, because myisamchk has no idea where the database is located. In fact, myisamchk does not actually care whether the files you are working on are located in a database directory. You can copy the files that correspond to a database table into some other location and perform recovery operations on them there.

如果您愿意,可以在 myisamchk 命令行上命名多个表。您也可以通过指定其索引文件(带有 .MYI 后缀的文件)来指定一个表。这使您可以通过使用模式 *.MYI 指定目录中的所有表。例如,如果您在一个数据库目录中,可以像这样检查该目录下的所有 MyISAM 表:You can name several tables on the myisamchk command line if you wish. You can also specify a table by naming its index file (the file with the .MYI suffix). This enables you to specify all tables in a directory by using the pattern *.MYI. For example, if you are in a database directory, you can check all the MyISAM tables in that directory like this:

myisamchk *.MYI

如果你不在数据库目录中,你可以通过指定目录的路径来检查那里的所有表:If you are not in the database directory, you can check all the tables there by specifying the path to the directory:

myisamchk /path/to/database_dir/*.MYI

你甚至可以通过使用 MySQL 数据目录路径的通配符来检查所有数据库中的所有表:You can even check all tables in all databases by specifying a wildcard with the path to the MySQL data directory:

myisamchk /path/to/datadir/*/*.MYI

快速检查所有 MyISAM 表的推荐方法是:The recommended way to quickly check all MyISAM tables is:

myisamchk --silent --fast /path/to/datadir/*/*.MYI

如果您想检查所有 MyISAM 表并修复任何损坏的表,可以使用以下命令:If you want to check all MyISAM tables and repair any that are corrupted, you can use the following command:

myisamchk --silent --force --fast --update-state \
          --key_buffer_size=64M --myisam_sort_buffer_size=64M \
          --read_buffer_size=1M --write_buffer_size=1M \
          /path/to/datadir/*/*.MYI

该命令假设您有超过 64MB 的可用空间。有关 myisamchk 内存分配的更多信息,请参见 第 6.6.4.6 节,“myisamchk 内存使用”。This command assumes that you have more than 64MB free. For more information about memory allocation with myisamchk, see Section 6.6.4.6, “myisamchk Memory Usage”.

有关使用 myisamchk 的更多信息,请参见 第 9.6 节,“MyISAM 表维护和崩溃恢复”。For additional information about using myisamchk, see Section 9.6, “MyISAM Table Maintenance and Crash Recovery”.

Important

您必须确保在运行 myisamchk 时,没有其他程序正在使用这些表。最有效的方法是在运行 myisamchk 时关闭 MySQL 服务器,或者锁定所有 myisamchk 正在使用的表。You must ensure that no other program is using the tables while you are running myisamchk. The most effective means of doing so is to shut down the MySQL server while running myisamchk, or to lock all tables that myisamchk is being used on.

否则,当您运行 myisamchk 时,可能会显示以下错误信息:Otherwise, when you run myisamchk, it may display the following error message:

warning: clients are using or haven't closed the table properly

这意味着您正在尝试检查一个已被另一个程序(例如 mysqld 服务器)更新的表,而该程序尚未关闭文件,或者在未正确关闭文件的情况下已终止,这有时可能导致一个或多个 MyISAM 表损坏。This means that you are trying to check a table that has been updated by another program (such as the mysqld server) that hasn't yet closed the file or that has died without closing the file properly, which can sometimes lead to the corruption of one or more MyISAM tables.

如果 mysqld 正在运行,您必须使用 FLUSH TABLES 强制将仍在内存中缓冲的表修改刷新。然后,您应该确保在运行 myisamchk 时无人使用这些表。If mysqld is running, you must force it to flush any table modifications that are still buffered in memory by using FLUSH TABLES. You should then ensure that no one is using the tables while you are running myisamchk

然而,避免此问题的最简单方法是使用 CHECK TABLE 来检查表,而不是使用 myisamchk。请参见 第 15.7.3.2 节,“CHECK TABLE 声明”。However, the easiest way to avoid this problem is to use CHECK TABLE instead of myisamchk to check tables. See Section 15.7.3.2, “CHECK TABLE Statement”.

myisamchk 支持以下选项,这些选项可以在命令行中指定,也可以在选项文件的 [myisamchk] 组中指定。有关 MySQL 程序使用的选项文件的信息,请参见 第 6.2.2.2 节,“使用选项文件”。myisamchk supports the following options, which can be specified on the command line or in the [myisamchk] group of an option file. For information about option files used by MySQL programs, see Section 6.2.2.2, “Using Option Files”.

表 6.17 myisamchk 选项Table 6.17 myisamchk Options

选项名称Option Name 说明Description
--分析--analyze 分析关键值的分布Analyze the distribution of key values
--备份--backup 将 .MYD 文件备份为 file_name-time.BAKMake a backup of the .MYD file as file_name-time.BAK
--块搜索--block-search 查找指定偏移量的块所属的记录Find the record that a block at the given offset belongs to
--字符集目录--character-sets-dir 可以找到字符集的目录Directory where character sets can be found
--检查--check 检查表格中的错误Check the table for errors
--仅检查更改--check-only-changed 仅检查自上次检查以来有变化的表Check only tables that have changed since the last check
--校正校验和--correct-checksum 纠正表格的校验和信息Correct the checksum information for the table
--数据文件长度--data-file-length 数据文件的最大长度(在数据文件已满时重新创建数据文件)Maximum length of the data file (when re-creating data file when it is full)
--调试--debug 写调试日志Write debugging log
--解码_位--decode_bits 解码位Decode_bits
--额外默认文件--defaults-extra-file 除了常规选项文件外,读取指定名称的选项文件Read named option file in addition to usual option files
--默认文件--defaults-file 仅读取指定的选项文件Read only named option file
--defaults-group-suffix(默认组后缀)--defaults-group-suffix 选项组后缀值Option group suffix value
--description(描述)--description 打印一些关于表的描述性信息Print some descriptive information about the table
--extend-check(扩展检查)--extend-check 进行非常彻底的表检查或修复,尝试从数据文件中恢复所有可能的行Do very thorough table check or repair that tries to recover every possible row from the data file
--快速--fast 仅检查未正确关闭的表格Check only tables that haven't been closed properly
--force 强制--force 如果 myisamchk 在表中发现任何错误,则自动执行修复操作Do a repair operation automatically if myisamchk finds any errors in the table
--force 覆盖旧的临时文件。与 -r 或 -o 选项一起使用Overwrite old temporary files. For use with the -r or -o option
--ft_max_word_len FULLTEXT 索引的最大单词长度Maximum word length for FULLTEXT indexes
--ft_min_word_len FULLTEXT 索引的最小单词长度Minimum word length for FULLTEXT indexes
--ft_stopword_file 使用此文件中的停用词,而不是内置列表Use stopwords from this file instead of built-in list
--帮助--HELP 显示帮助信息并退出Display help message and exit
--帮助--help 显示帮助信息并退出Display help message and exit
--信息--information 打印有关被检查表的信息统计Print informational statistics about the table that is checked
--key_buffer_size 用于 MyISAM 表索引块的缓冲区大小Size of buffer used for index blocks for MyISAM tables
--已使用密钥--keys-used 一个表示要更新哪些索引的位值A bit-value that indicates which indexes to update
--最大记录长度--max-record-length 如果 myisamchk 无法分配内存来存储它们,则跳过大于给定长度的行Skip rows larger than the given length if myisamchk cannot allocate memory to hold them
--medium-check 进行比 --extend-check 操作更快速的检查Do a check that is faster than an --extend-check operation
--myisam_block_size 用于 MyISAM 索引页的块大小Block size to be used for MyISAM index pages
--myisam_sort_buffer_size 在执行 REPAIR 时或使用 CREATE INDEX 或 ALTER TABLE 创建索引时分配的排序索引缓冲区The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE
--无默认值--no-defaults 不读取任何选项文件Read no option files
--并行恢复--parallel-recover 使用与 -r 和 -n 相同的技术,但以并行方式创建所有密钥,使用不同的线程(测试版)Uses the same technique as -r and -n, but creates all the keys in parallel, using different threads (beta)
--打印默认值--print-defaults 打印默认选项Print default options
--快速--quick 通过不修改数据文件来实现更快的修复Achieve a faster repair by not modifying the data file
--读取缓冲区大小--read_buffer_size 每个执行顺序扫描的线程为它扫描的每个表分配一个此大小的缓冲区Each thread that does a sequential scan allocates a buffer of this size for each table it scans
--只读--read-only 不要将表格标记为已检查Do not mark the table as checked
--恢复--recover 进行一次几乎可以修复任何问题的修复,除了那些不唯一的唯一键Do a repair that can fix almost any problem except unique keys that aren't unique
--安全恢复--safe-recover 使用旧的恢复方法进行修复,该方法按顺序读取所有行,并根据找到的行更新所有索引树Do a repair using an old recovery method that reads through all rows in order and updates all index trees based on the rows found
--设置自增--set-auto-increment 强制新记录的 AUTO_INCREMENT 编号从给定值开始Force AUTO_INCREMENT numbering for new records to start at the given value
--设置校对规则--set-collation 指定用于排序表索引的排序规则Specify the collation to use for sorting table indexes
--静默--silent 静音模式Silent mode
--sort_buffer_size 在执行 REPAIR 时或使用 CREATE INDEX 或 ALTER TABLE 创建索引时分配的排序索引缓冲区The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE
--sort-index 按高到低顺序对索引树块进行排序Sort the index tree blocks in high-low order
--sort_key_blocks sort_key_blocks
--排序记录--sort-records 根据特定索引对记录进行排序Sort records according to a particular index
--排序恢复--sort-recover 即使临时文件非常大,也强制 myisamchk 使用排序来解决键问题Force myisamchk to use sorting to resolve the keys even if the temporary files would be very large
--统计方法--stats_method 指定 MyISAM 索引统计收集代码应如何处理 NULLSpecifies how MyISAM index statistics collection code should treat NULLs
--tmpdir 用于存储临时文件的目录Directory to be used for storing temporary files
--解压--unpack 解压使用 myisampack 打包的表Unpack a table that was packed with myisampack
--update-state 将信息存储在 .MYI 文件中,以指示表何时被检查以及表是否崩溃Store information in the .MYI file to indicate when the table was checked and whether the table crashed
--详细模式--verbose 详细模式Verbose mode
--版本--version 显示版本信息并退出Display version information and exit
--等待--wait 等待锁定的表被解锁,而不是终止Wait for locked table to be unlocked, instead of terminating
--写入缓冲区大小--write_buffer_size 写入缓冲区大小Write buffer size