mysqlsizemyisam

MyISAM files size has increased (doubled)


One of my table's file size (a .MYD file) has increased by about 100%. If I look into the data there is just a normal daily load during the last few days. What could have caused this file size increase?

myisamchk

As suggested by a user I tried sudo myisamchk -r tablename. The result of this operation was "Fixing index 1" "Fixing index 2" ... and the exact same file size.

Edit: After running the command a second time the file size decreased to the normal (half) size.


Solution

  • @e4c5 has the most likely answer. He is asking you to remove the deleted rows. MySQL will not reclaim the space from deleted rows. As more and more rows are deleted, the larger your .MYD becomes. The only way to reclaim the space is to rebuild the .MYD - either by recreating the table, using the optimize table command or running myisamchk -r.

    The following command will rebuild the table.

    optimize table $table_name;
    

    The myisamchk -r command line approach works too - but be sure the table is locked to prevent users from accessing it (otherwise you run the very real risk of losing data). Be sure to flush table before using it again after running myisamchk repair or MySQL will detect the table has changed and run an unnecessary check against it. Of the three methods, myisamchk -r is the most prone to data lost (but still my preferred method- you just have to be careful and prepared for the worst).