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
.MYDfile (data file) and.MYIfile (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=InnoDBor rely oninnodb_file_per_table.