phpMyAdmin can remove a selected group of WordPress comments directly from the database. This guide shows an advanced SQL method for deleting ordinary spam comments and their metadata when normal WordPress tools are unavailable.
Before you start
Use the WordPress Comments screen for routine bulk deletion. It handles comment relationships and plugin actions that direct SQL bypasses.
Back up the database and confirm its name and table prefix in wp-config.php. Replace wp_ in every table name below if the installation uses another prefix. Pause comment submissions while previewing and deleting so the selected data does not change between steps.
Direct SQL deletion is permanent. Do not empty the entire comments table: plugins may store reviews, order notes or other records there. The example below targets ordinary spam comments without replies, not every record marked as spam.
Preview the selection
Open the correct database in phpMyAdmin, select SQL and run:
SELECT c.comment_ID, c.comment_post_ID, c.comment_author, c.comment_content
FROM wp_comments AS c
LEFT JOIN wp_comments AS reply ON reply.comment_parent = c.comment_ID
WHERE c.comment_approved = 'spam'
AND c.comment_type IN ('', 'comment')
AND reply.comment_ID IS NULL;Review every intended match and record the affected post IDs. Comments with replies are deliberately excluded and should be handled through WordPress.
Delete the selected comments and metadata
After checking the preview, run the matching deletion:
DELETE c, m
FROM wp_comments AS c
LEFT JOIN wp_commentmeta AS m ON m.comment_id = c.comment_ID
LEFT JOIN wp_comments AS reply ON reply.comment_parent = c.comment_ID
WHERE c.comment_approved = 'spam'
AND c.comment_type IN ('', 'comment')
AND reply.comment_ID IS NULL;Check for errors and run the preview again. An affected-row total can include metadata rows as well as comments.
Finish the checks
Have an administrator refresh relevant caches and recount comments for the recorded post IDs. With WP-CLI available, a command such as the following runs from this site’s WordPress directory:
wp comment recount 123 456Replace the example IDs with the affected post IDs. Check the website and any comment-related plugins before resuming submissions.