4.6.4 myisamchk — MyISAM Table-Maintenance UtilityMyISAM表维护实用程序

4.6.4.1 myisamchk General Optionsmyisamchk常规选项
4.6.4.2 myisamchk Check Optionsmyisamchk检查选项
4.6.4.3 myisamchk Repair Optionsmyisamchk修复选项
4.6.4.4 Other myisamchk Options其他myisamchk选项
4.6.4.5 Obtaining Table Information with myisamchk用myisamchk获取表信息
4.6.4.6 myisamchk Memory Usagemyisamchk内存使用情况

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

You can also use the CHECK TABLE and REPAIR TABLE statements to check and repair MyISAM tables. 您还可以使用CHECK TABLEREPAIR TABLE语句来检查和修复MyISAM表。See Section 13.7.3.2, “CHECK TABLE Statement”, and Section 13.7.3.5, “REPAIR TABLE Statement”.请参阅第13.7.3.2节,“CHECK TABLE语句”第13.7.3.5节,“REPAIR TABLE语句”

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

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.最好在执行表修复操作之前备份表;在某些情况下,该操作可能会导致数据丢失。可能的原因包括但不限于文件系统错误。

Invoke myisamchk like this:像这样调用myisamchk

myisamchk [options] tbl_name ...

The options specify what you want myisamchk to do. 这些options指定了您希望myisamchk执行的操作。They are described in the following sections. You can also get a list of options by invoking myisamchk --help.以下章节将对其进行描述。您还可以通过调用myisamchk -help来获取选项列表。

With no options, myisamchk simply checks your table as the default operation. 没有选项,myisamchk只是将您的表作为默认操作进行检查。To get more information or to tell myisamchk to take corrective action, specify options as described in the following discussion.要获取更多信息或告诉myisamchk采取纠正措施,请按照以下讨论中的描述指定选项。

tbl_name is the database table you want to check or repair. tbl_name是您要检查或修复的数据库表。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. 如果在数据库目录之外的其他位置运行myisamchk,则必须指定数据库目录的路径,因为myisamck不知道数据库的位置。In fact, myisamchk does not actually care whether the files you are working on are located in a database directory. 事实上,myisamchk实际上并不关心您正在处理的文件是否位于数据库目录中。You can copy the files that correspond to a database table into some other location and perform recovery operations on them there.您可以将与数据库表对应的文件复制到其他位置,并在那里对其执行恢复操作。

You can name several tables on the myisamchk command line if you wish. 如果你愿意,你可以在myisamchk命令行上命名几个表。You can also specify a table by naming its index file (the file with the .MYI suffix). 您还可以通过命名表的索引文件(后缀为.MYI的文件)来指定表。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:这使您能够使用模式*.MYI指定目录中的所有表。例如,如果你在数据库目录中,你可以像这样检查该目录中的所有MyISAM表:

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

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

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

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

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

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

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

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

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

Important重要

You must ensure that no other program is using the tables while you are running myisamchk. 您必须确保在运行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时关闭MySQL服务器,或者锁定myisamck正在使用的所有表。

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

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

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服务器)更新的表,该程序尚未关闭文件,或者在没有正确关闭文件的情况下死亡,这有时会导致一个或多个MyISAM表损坏。

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

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

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

Table 4.19 myisamchk Options选项

Option Name选项名称Description描述
--analyzeAnalyze the distribution of key values分析关键值的分布
--backupMake a backup of the .MYD file as file_name-time.BAK将.MYD文件备份为file_name-time.BAK
--block-searchFind the record that a block at the given offset belongs to找到给定偏移量的块所属的记录
--checkCheck the table for errors检查表格是否有错误
--check-only-changedCheck only tables that have changed since the last check仅检查自上次检查以来已更改的表
--correct-checksumCorrect the checksum information for the table更正表的校验和信息
--data-file-lengthMaximum length of the data file (when re-creating data file when it is full)数据文件的最大长度(当数据文件已满时重新创建时)
--debugWrite debugging log写入调试日志
--decode_bitsDecode_bits
--defaults-extra-fileRead named option file in addition to usual option files除了常规选项文件外,还读取命名选项文件
--defaults-fileRead only named option file只读命名选项文件
--defaults-group-suffixOption group suffix value选项组后缀值
--descriptionPrint some descriptive information about the table打印一些关于表格的描述性信息
--extend-checkDo very thorough table check or repair that tries to recover every possible row from the data file执行非常彻底的表检查或修复,尝试从数据文件中恢复所有可能的行
--fastCheck only tables that haven't been closed properly仅检查未正确关闭的表
--forceDo a repair operation automatically if myisamchk finds any errors in the table如果myisamchk在表中发现任何错误,则自动执行修复操作
--forceOverwrite old temporary files. For use with the -r or -o option覆盖旧的临时文件。与-r-o选项一起使用
--ft_max_word_lenMaximum word length for FULLTEXT indexesFULLTEXT索引的最大字长
--ft_min_word_lenMinimum word length for FULLTEXT indexesFULLTEXT索引的最小字长
--ft_stopword_fileUse stopwords from this file instead of built-in list使用此文件中的停用词,而不是内置列表
--HELPDisplay help message and exit显示帮助消息并退出
--helpDisplay help message and exit显示帮助消息并退出
--informationPrint informational statistics about the table that is checked打印所检查表的信息统计信息
--key_buffer_sizeSize of buffer used for index blocks for MyISAM tables用于MyISAM表索引块的缓冲区大小
--keys-usedA bit-value that indicates which indexes to update指示要更新哪些索引的位值
--max-record-lengthSkip rows larger than the given length if myisamchk cannot allocate memory to hold them如果myisamchk无法分配内存来保存大于给定长度的行,则跳过这些行
--medium-checkDo a check that is faster than an --extend-check operation执行比--extend-check操作更快的检查
--myisam_block_sizeBlock size to be used for MyISAM index pages用于MyISAM索引页的块大小
--myisam_sort_buffer_sizeThe buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE在执行REPAIR或使用CREATE INDEXALTER TABLE创建索引时对索引进行排序时分配的缓冲区
--no-defaultsRead no option files不读取选项文件
--parallel-recoverUses the same technique as -r and -n, but creates all the keys in parallel, using different threads (beta)使用与-r和-n相同的技术,但使用不同的线程并行创建所有键(测试版)
--print-defaultsPrint default options打印默认选项
--quickAchieve a faster repair by not modifying the data file通过不修改数据文件实现更快的修复
--read_buffer_sizeEach thread that does a sequential scan allocates a buffer of this size for each table it scans执行顺序扫描的每个线程为它扫描的每个表分配一个此大小的缓冲区
--read-onlyDo not mark the table as checked不要将表格标记为已选中
--recoverDo a repair that can fix almost any problem except unique keys that aren't unique进行修复,几乎可以解决任何问题,除了不是唯一的唯一密钥
--safe-recoverDo 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-incrementForce AUTO_INCREMENT numbering for new records to start at the given value强制新记录的AUTO_INCREMENT编号从给定值开始
--set-collationSpecify the collation to use for sorting table indexes指定用于对表索引进行排序的排序规则
--silentSilent mode静音模式
--sort_buffer_sizeThe buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE在执行REPAIR或使用CREATE INDEXALTER TABLE创建索引时对索引进行排序时分配的缓冲区
--sort-indexSort the index tree blocks in high-low order按高低顺序对索引树块进行排序
--sort_key_blockssort_key_blocks
--sort-recordsSort records according to a particular index根据特定索引对记录进行排序
--sort-recoverForce myisamchk to use sorting to resolve the keys even if the temporary files would be very large强制myisamchk使用排序来解析密钥,即使临时文件非常大
--stats_methodSpecifies how MyISAM index statistics collection code should treat NULLs指定MyISAM索引统计信息收集代码应如何处理NULL
--tmpdirDirectory to be used for storing temporary files用于存储临时文件的目录
--unpackUnpack a table that was packed with myisampack打开装满myisampack的表格
--update-stateStore information in the .MYI file to indicate when the table was checked and whether the table crashed将信息存储在MYI文件中,以指示表何时被检查以及表是否崩溃
--verboseVerbose mode详细模式
--versionDisplay version information and exit显示版本信息并退出
--write_buffer_sizeWrite buffer size写入缓冲区大小

4.6.4.1 myisamchk General Options
4.6.4.2 myisamchk Check Options
4.6.4.3 myisamchk Repair Options
4.6.4.4 Other myisamchk Options
4.6.4.5 Obtaining Table Information with myisamchk
4.6.4.6 myisamchk Memory Usage