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.

Back when this was written, myisamchk only accepted sort_buffer_size for “Repair by sort”, which is what made this error so confusing. On modern MySQL (since 5.5.29 / 5.6.9) that’s no longer the case: myisamchk now accepts --myisam_sort_buffer_size directly, and --sort_buffer_size is kept around as a deprecated synonym for it.

The following increases the buffer size that is needed.

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

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