MySQL – How to Fix Terribly Slow Disk Read When Repairing MyISAM Table

myisamMySQL

So I've launched the myisamchk utility with repair option on all tables within the database.

Smaller tables (1GB max) got fixed in no time, virtually seconds. However, my largest table (9GB) takes forever (20mb/min) to fix. My server is down because of that.

I've checked 'iotop -ao' and this is what i got:

IOTOP dump

Whats going on here? The read of 300 KB/S is VERY HIGH in this screenshot, i was aiming at capturing the super-fast write. Sometimes the read spikes to 5-10 MB/s, but for the rest of the time its within 0-50KB/s range.

The table has only several columns, 2 indexes (1) Long, (2) Varchar(72). Mysql 5.5.56, CentOS 6. Its doing repair by sort.

Best Answer

To anyone whom it may concern;

The problem of such slow disk read lies in the fragmentation of the data. A subsequent repair of the same table gives very high disk read i/o, indicating sequential access as opposed to random access.

The table has plenty of deleted rows, and the newly inserted records must then be read in a random fashion, resulting in slow read speeds. Again, after the table was repaired, the records where stored sequentially, and the same repair operation gave very fast results. I guess this is another reason to use InnoDB over MyISAM.

Thanks, Michael.