In MySQL MyISAM tables how do you free up disk space after deleting a lot of records in a table?

In MySQL with MyISAM tables, deleting rows does not automatically shrink the physical .MYD data file. To reclaim disk space after large deletions, you need to run:

OPTIMIZE TABLE your_table_name;

🔧 What OPTIMIZE TABLE does for MyISAM:

  • Rewrites the entire .MYD file (data file) and .MYI file (index file).
  • Removes unused space left by deleted rows.
  • Reorders and defragments indexes.
  • Frees up disk space and improves performance.

🛠️ Example:

OPTIMIZE TABLE suppression.mailserverdomains_segfilter;

After running this, check the file size:

ls -lh /var/lib/mysql/suppression/mailserverdomains_segfilter.*

You should see .MYD shrink if deletions were significant.


⚠️ Notes:

  • This operation locks the table during optimization.
  • It can be slow on large tables — consider running during off-peak hours.
  • Works only for MyISAM — for InnoDB, you’d use ALTER TABLE ... ENGINE=InnoDB or rely on innodb_file_per_table.

Leave a Reply