MySQL – myisamchk: error: myisam_sort_buffer_size is too small

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 19, 2010

Follow me on Twitter as @mattiasgeniar

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 that is needed.

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

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



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.