The myisamchk utility gets information about your database tables or checks, repairs, or optimizes them. myisamchk实用程序获取有关数据库表的信息,或检查、修复或优化它们。myisamchk works with myisamchk用于MyISAM
tables (tables that have .MYD
and .MYI
files for storing data and indexes).MyISAM
表(具有用于存储数据和索引的.MYD
和.MYI
文件的表)。
You can also use the 您还可以使用CHECK TABLE
and REPAIR TABLE
statements to check and repair MyISAM
tables. CHECK TABLE
和REPAIR 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。
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
表维护和崩溃恢复”。
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 这意味着您正试图检查一个已被另一个程序(如mysqld服务器)更新的表,该程序尚未关闭文件,或者在没有正确关闭文件的情况下死亡,这有时会导致一个或多个MyISAM
tables.MyISAM
表损坏。
If mysqld is running, you must force it to flush any table modifications that are still buffered in memory by using 如果mysqld正在运行,则必须使用FLUSH TABLES
. 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支持以下选项,这些选项可以在命令行或选项文件的[myisamchk]
group of an option file. [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选项
--analyze | |
--backup | |
--block-search | |
--check | |
--check-only-changed | |
--correct-checksum | |
--data-file-length | |
--debug | |
--decode_bits | Decode_bits |
--defaults-extra-file | |
--defaults-file | |
--defaults-group-suffix | |
--description | |
--extend-check | |
--fast | |
--force | |
--force | -r 或-o 选项一起使用 |
--ft_max_word_len | |
--ft_min_word_len | |
--ft_stopword_file | |
--HELP | |
--help | |
--information | |
--key_buffer_size | MyISAM 表索引块的缓冲区大小 |
--keys-used | |
--max-record-length | |
--medium-check | --extend-check 操作更快的检查 |
--myisam_block_size | MyISAM 索引页的块大小 |
--myisam_sort_buffer_size | REPAIR 或使用CREATE INDEX 或ALTER TABLE 创建索引时对索引进行排序时分配的缓冲区 |
--no-defaults | |
--parallel-recover | |
--print-defaults | |
--quick | |
--read_buffer_size | |
--read-only | |
--recover | |
--safe-recover | |
--set-auto-increment | |
--set-collation | |
--silent | |
--sort_buffer_size | REPAIR 或使用CREATE INDEX 或ALTER TABLE 创建索引时对索引进行排序时分配的缓冲区 |
--sort-index | |
--sort_key_blocks | sort_key_blocks |
--sort-records | |
--sort-recover | |
--stats_method | MyISAM 索引统计信息收集代码应如何处理NULL |
--tmpdir | |
--unpack | |
--update-state | |
--verbose | |
--version | |
--write_buffer_size |