How to Quickly Clear Thousands of WordPress Spam Comments
When you run a WordPress site, it’s inevitable that spam comments will find their way into your blog. Plugins like Akismet do a good job at weeding out the spam, separating them from the normal comments.
If you login to WordPress to find that your site has accumulated thousands of spam comments, the first thing you may think of doing is to hit that “Empty Spam” button. This is useful for clearing spam when the number is smaller. When you have thousands of spam, clicking this button can take a long time, and even cause a timeout on the server.
There’s a far quicker way to clear the spam, via this simple SQL command in phpMyAdmin:
DELETE FROM wp_comments WHERE comment_approved = "spam"; DELETE FROM wp_commentmeta WHERE meta_key LIKE "akismet_%";
And voila! The spam gets cleared out in seconds.
After manually clearing the spam in the database, you may also notice an overhead in the wp_comment and wp_commentmeta tables. You can optimise these 2 tables like this:
OPTIMIZE TABLE wp_comments; OPTIMIZE TABLE wp_commentmeta;