Memory allocation is important when you run myisamchk. myisamchk uses no more memory than its memory-related variables are set to. If you are going to use myisamchk on very large tables, you should first decide how much memory you want it to use. The default is to use only about 3MB to perform repairs. By using larger values, you can get myisamchk to operate faster. For example, if you have more than 32MB RAM, you could use options such as these (in addition to any other options you might specify):
shell>myisamchk --sort_buffer_size=16M --key_buffer_size=16M \--read_buffer_size=1M --write_buffer_size=1M ...
Using --sort_buffer_size=16M should probably
be enough for most cases.
Be aware that myisamchk uses temporary
files in TMPDIR. If
TMPDIR points to a memory filesystem, you
may easily get out of memory errors. If this happens, run
myisamchk with the
--tmpdir=
option to specify some directory located on a filesystem that
has more space.
path
When repairing, myisamchk also needs a lot of disk space:
Double 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. This space must be available
on the same filesystem 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 filesystem as the original data file.
When using --recover or
--sort-recover (but not when using
--safe-recover), you need space for a
sort buffer. 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. This space
is allocated in the temporary directory (specified by
TMPDIR or
--tmpdir=).
path
If you have a problem with disk space during repair, you can
try --safe-recover instead of
--recover.

User Comments
In MySQL 4.1.1, myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ... does not work.
Instead, use
myisamchk --sort_key_blocks=16M --key_cache_block_size=16M --read_buffer_size=1M --write=1M
This part of the manual is outdated. Using the -o option to set variables is depricated. Type myisamchk --help for more info.
On modern servers with several GB of RAM something like the following can make the difference between waiting 4 hours or waiting only 15 minutes for a large table to repair:
myisamchk --sort_buffer_size=100M --key_buffer_size=100M --read_buffer_size=25M --write_buffer_size=25M -r /path/to/table
Add your own comment.