MySQL – myisamchk: error: myisam_sort_buffer_size is too small

If you’re trying to repair large MyISAM tables in MySQL, you can run into the following restriction, because of the limited size of the default Sort Buffer.

srv # myisamchk -r table.MYI
- recovering (with sort) MyISAM-table 'table.MYI'
Data records: 335045
- Fixing index 1
Found block that points outside data file at 1509428340
Found link that points at 61778810452273 (outside data file) at 1509428348
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5
- Fixing index 6
- Fixing index 7
- Fixing index 8
myisamchk: error: myisam_sort_buffer_size is too small
MyISAM-table 'table.MYI' is not fixed because of errors

While the fix seems obvious (increase the myisam_sort_buffer_size), it’s a bit confusing.

The MySQL server knows 2 variables, myisam_sort_buffer_size and sort_buffer_size. The first one is the one used for the buffer in “Repair by sort”. The second one is used to buffer a filesort.

The myisamchk command does not have myisam_sort_buffer_size. myisamchk has only sort_buffer_size, which is used for “Repair by sort”.

The following increases the buffer size.

srv # myisamchk -r -q table.MYI --sort_buffer_size=2G

Or increase the memory, if it’s still not sufficient to do the repair.