- 4.6.4.1 myisamchk常规选项
- 4.6.4.2 myisamchk检查选项
- 4.6.4.3 myisamchk修复选项
- 4.6.4.4其他myisamchk选项
- 4.6.4.5使用myisamchk获取表信息
- 4.6.4.6 myisamchk内存使用情况
该myisamchk的程序获取有关数据库表或检查,修理,或将其提供更优的信息。 myisamchk的作品与 MyISAM表(有表 .MYD和.MYI文件存储数据和索引)。
您也可以使用CHECK TABLE andREPAIR TABLE语句检查和修复MyISAM表。请参见 第13.7.3.2节“ CHECK TABLE语句”和 第13.7.3.5节“ REPAIR TABLE语句”。
不支持 将myisamchk与分区表一起使用。
警告
最好在执行表修复操作之前先备份表。在某些情况下,该操作可能会导致数据丢失。可能的原因包括但不限于文件系统错误。
像这样 调用myisamchk:
shell> myisamchk [options] tbl_name ...
在*options*你想要的指定 myisamchk的做。以下各节将对它们进行描述。您还可以通过调用myisamchk --help来获得选项列表。
没有任何选项,myisamchk只会将表作为默认操作进行检查。要获取更多信息或告诉myisamchk采取纠正措施,请按照以下讨论中的说明指定选项。
*tbl_name*是您要检查或修复的数据库表。如果 在数据库目录之外的其他位置运行myisamchk,则必须指定数据库目录的路径,因为 myisamchk不知道数据库的位置。实际上,myisamchk实际上并不关心您正在处理的文件是否位于数据库目录中。您可以将与数据库表对应的文件复制到其他位置,然后在该位置执行恢复操作。
如果愿意, 可以在myisamchk命令行上命名几个表。您也可以通过命名其索引文件(带.MYI 后缀的文件)来指定表。这使您可以使用模式指定目录中的所有表*.MYI。例如,如果您在数据库目录中,则可以MyISAM像这样检查该目录中的所有 表:
shell> myisamchk *.MYI
如果您不在数据库目录中,则可以通过指定目录的路径来检查那里的所有表:
shell> myisamchk /path/to/database_dir/*.MYI
您甚至可以通过指定通配符以及MySQL数据目录的路径来检查所有数据库中的所有表:
shell> myisamchk /path/to/datadir/*/*.MYI
快速检查所有MyISAM表的推荐方法 是:
shell> myisamchk --silent --fast /path/to/datadir/*/*.MYI
如果要检查所有MyISAM表并修复已损坏的表,可以使用以下命令:
shell> 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进行内存分配的更多信息 ,请参见 第4.6.4.6节“ myisamchk内存使用情况”。
有关使用myisamchk的更多信息 ,请参见 第7.6节“ MyISAM表维护和崩溃恢复”。
重要
*在运行myisamchk*时,必须确保没有其他程序在使用这些表 。这样做的最有效方法是在运行myisamchk时关闭MySQL服务器,或锁定正在使用myisamchk的所有表。
否则,当您运行myisamchk时,它可能会显示以下错误消息:
warning: clients are using or haven't closed the table properly
这意味着您正在尝试检查由另一个程序(例如mysqld服务器)更新的表,该程序 尚未关闭文件或在未正确关闭文件的情况下死亡,这有时会导致损坏一个或多个 MyISAM表。
如果mysqld正在运行,则必须使用强制其刷新仍在内存中缓冲的所有表修改FLUSH TABLES。然后,您应该确保在运行myisamchk时没有人使用这些表。
但是,避免此问题的最简单方法是使用 myisamchkCHECK TABLE代替 检查表。请参见 第13.7.3.2节“ CHECK TABLE语句”。
myisamchk支持以下选项,可以在命令行或[myisamchk]选项文件的 组中指定这些选项。有关MySQL程序使用的选项文件的信息,请参见 第4.2.2.2节“使用选项文件”。
表4.19 myisamchk选项
| Option Name | Description |
|---|---|
| –analyze | Analyze the distribution of key values |
| –backup | Make 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 |
| –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 | Option group suffix value |
| –description | Print some descriptive information about the table |
| –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 | Do a repair operation automatically if myisamchk finds any errors in the table |
| –force | Overwrite old temporary files. For use with the -r or -o option |
| –ft_max_word_len | Maximum word length for FULLTEXT indexes |
| –ft_min_word_len | 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 | Size of buffer used for index blocks for MyISAM tables |
| –keys-used | A bit-value that indicates which indexes to update |
| –max-record-length | Skip rows larger than the given length if myisamchk cannot allocate memory to hold them |
| –medium-check | Do a check that is faster than an --extend-check operation |
| –myisam_block_size | Block size to be used for MyISAM index pages |
| –myisam_sort_buffer_size | 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 | 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 | 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 | 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 | Force myisamchk to use sorting to resolve the keys even if the temporary files would be very large |
| –stats_method | Specifies how MyISAM index statistics collection code should treat NULLs |
| –tmpdir | Directory to be used for storing temporary files |
| –unpack | Unpack a table that was packed with myisampack |
| –update-state | 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 |
| –write_buffer_size | Write buffer size |




