If your WordPress site is overwhelmed with thousands of spam or pending comments, manually deleting them through the WordPress dashboard can be slow and inefficient. Fortunately, you can use phpMyAdmin to delete these unwanted comments in bulk directly from your database. If you need a plugin for this process click here to delete massive amounts of spam.
Before You Begin: Backup Your Database
Before making any changes to your database, it is highly recommended to create a full backup of your WordPress database. You can do this via phpMyAdmin or use a WordPress backup plugin.
Steps to Backup Your Database in phpMyAdmin:
Log in to your cPanel or web hosting dashboard.
Locate and open phpMyAdmin.
Select your WordPress database from the left panel.
Click on the Export tab at the top.
Choose Quick – display only the minimal options, then click Go.
Download and save the backup file.
Method 1: Deleting All Pending Comments in phpMyAdmin
If you have a large number of pending comments that you want to remove, you can run the following SQL query:
DELETE FROM wp_comments WHERE comment_approved = '0';
Explanation:
wp_comments
is the table that stores all comments.comment_approved = '0'
refers to pending comments that have not been approved.
This query will delete all comments that are still awaiting moderation.
Method 2: Deleting All Spam Comments in phpMyAdmin
If your site has been flooded with spam comments, you can remove them all using the following query:
DELETE FROM wp_comments WHERE comment_approved = 'spam';
Explanation:
comment_approved = 'spam'
ensures only spam comments are deleted.This will not affect approved or pending comments.
Method 3: Empty the Comments Table (Delete All Comments)
If you want to delete all comments (including approved, pending, spam, and trash), you can completely empty the wp_comments
table:
TRUNCATE TABLE wp_comments;
Explanation:
This command will delete all comments permanently and reset the comment table.
Be cautious, as this action cannot be undone unless you have a backup.
Additionally, you may want to clear comment meta data:
TRUNCATE TABLE wp_commentmeta;
This will remove any leftover metadata associated with the deleted comments.
Method 4: Deleting Comments by a Specific Author or Email
If spam is coming from a specific user, you can delete their comments by email:
DELETE FROM wp_comments WHERE comment_author_email = '[email protected]';
Or by author name:
DELETE FROM wp_comments WHERE comment_author = 'Spam Bot';
Final Steps: Optimize Your Database
After deleting thousands of comments, it's a good idea to optimize the database to reclaim storage space and improve performance. Run this query in phpMyAdmin:
OPTIMIZE TABLE wp_comments; OPTIMIZE TABLE wp_commentmeta;
This will clean up any fragmentation left after the deletion process.
Conclusion
Using phpMyAdmin to delete large amounts of spam or pending comments in WordPress is a fast and efficient method compared to manually deleting them from the dashboard. Always remember to back up your database before making changes, and optimize your database after mass deletions to maintain performance.
By following these steps, you can keep your WordPress comments section clean and free of spam. 🚀