How to Delete WordPress Comments From the Command Line (CLI)

Haven’t logged into your wordpress blog for a while? Find a few thousand spam comments that you need to delete? I had 34,020 comments in my spam queue. Here is how you can delete them without doing it 20 at a time =P

1. Log into mysql (mysql -u root -p)
2. Select the appropriate database (probably starts with wp-). Look in your wp-config.php file to find the name of your database if you don’t remember what it is.
3. Enter the following command (WARNING: This will delete any comment that has not been marked ‘approved’):
DELETE FROM wp_comments WHERE comment_approved = 0;

Enjoy

Leave a Reply