Skip to main content

Fixing invisible bloat from comments in a Wordpress database

When upgrading my installation of Wordpress today, I noticed that the related MySQL tables had grown to a few hundred megabytes. It turned out to be (invisible but kept) spam comments (in table wp_comments) and Akismet analysis results (all of table wp_commentmeta). This is what got my database down to 6 MB again (make backups before, no warrenty!):

TRUNCATE wp_commentmeta;
OPTIMIZE TABLE wp_commentmeta;

DELETE FROM wp_comments WHERE comment_approved = "spam";
OPTIMIZE TABLE wp_comments;