Memory allocation is important when you run myisamchk. myisamchk uses no more memory than its memory-related variables are set to. 运行myisamchk时,内存分配很重要。myisamchk使用的内存不超过其内存相关变量的设置值。If you are going to use myisamchk on very large tables, you should first decide how much memory you want it to use. 如果你要在非常大的表上使用myisamchk,你应该首先决定你想要它使用多少内存。The default is to use only about 3MB to perform repairs. 默认情况下,仅使用约3MB进行维修。By using larger values, you can get myisamchk to operate faster. 通过使用更大的值,你可以让myisamchk运行得更快。For example, if you have more than 512MB RAM available, you could use options such as these (in addition to any other options you might specify):例如,如果您有超过512MB的可用RAM,则可以使用以下选项(除了您可能指定的任何其他选项):
myisamchk --myisam_sort_buffer_size=256M \
           --key_buffer_size=512M \
           --read_buffer_size=64M \
           --write_buffer_size=64M ...
Using 在大多数情况下,使用--myisam_sort_buffer_size=16M is probably enough for most cases.--myisam_sort_buffer_size=16M可能就足够了。
Be aware that myisamchk uses temporary files in 请注意,myisamchk在TMPDIR. TMPDIR中使用临时文件。If 如果TMPDIR points to a memory file system, out of memory errors can easily occur. TMPDIR指向内存文件系统,则很容易发生内存不足错误。If this happens, run myisamchk with the 如果发生这种情况,请使用--tmpdir= option to specify a directory located on a file system that has more space.dir_name--tmpdir=dir_name选项运行myisamchk,以指定位于具有更多空间的文件系统上的目录。
When performing repair operations, myisamchk also needs a lot of disk space:在执行修复操作时,myisamchk还需要大量的磁盘空间:
Twice the size of the data file (the original file and a copy). 数据文件大小的两倍(原始文件和副本)。This space is not needed if you do a repair with 如果您使用--quick; in this case, only the index file is re-created. --quick进行维修,则不需要此空间;在这种情况下,只会重新创建索引文件。This space must be available on the same file system as the original data file, as the copy is created in the same directory as the original.此空间必须与原始数据文件在同一文件系统上可用,因为副本是在与原始文件相同的目录中创建的。
Space for the new index file that replaces the old one. The old index file is truncated at the start of the repair operation, so you usually ignore this space. This space must be available on the same file system as the original data file.用于替换旧索引文件的新索引文件的空间。旧索引文件在修复操作开始时被截断,因此您通常会忽略此空间。此空间必须与原始数据文件位于同一文件系统上。
When using 使用--recover or --sort-recover (but not when using --safe-recover), you need space on disk for sorting. --recover或--sort-recover时(但不使用--safe-recover时),您需要磁盘上的空间进行排序。This space is allocated in the temporary directory (specified by 此空间在临时目录中分配(由TMPDIR or --tmpdir=). dir_nameTMPDIR或--tmpdir=dir_name指定)。The following formula yields the amount of space required:以下公式得出所需的空间量:
(largest_key+row_pointer_length) *number_of_rows* 2
You can check the length of the keys and the 您可以使用row_pointer_length with myisamchk -dv tbl_name (see Section 4.6.4.5, “Obtaining Table Information with myisamchk”). myisamchk-dv tbl_name检查密钥的长度和row_pointer_length(请参阅第4.6.4.5节,“使用myisapchk获取表信息”)。The row_pointer_length and number_of_rows values are the Datafile pointer and Data records values in the table description. row_pointer_length和number_of_rows值是表描述中的数据文件游标和数据记录值。To determine the 要确定largest_key value, check the Key lines in the table description. largest_key值,请检查表描述中的key行。The Len column indicates the number of bytes for each key part. For a multiple-column index, the key size is the sum of the Len values for all key parts.Len列表示每个关键部分的字节数。对于多列索引,键大小是所有键部分的Len值之和。
If you have a problem with disk space during repair, you can try 如果在修复过程中磁盘空间有问题,可以尝试使用--safe-recover instead of --recover.--safe-recover而不是--recover。