Removing WordPress Comments using SQL Queries

WordPress comments can take up a lot of space and slow down your website’s load time. Here are the various database queries to remove bulk comments directly from the database.

First, log into phpMyAdmin. Then select the database of your WordPress site in the left-hand column. Click the SQL tab and enter the following queries

1. Removing WordPress comments from a specific user

DELETE from wp_comments WHERE comment_author_email = 'email address'

  • Update the command for your situation as follows:
    • email address is email address associated with the comments you want to remove 
    • Warning: If your WordPress database uses custom table prefixes, then you must replace wp_ in each command with the prefix listed in your wp-config.php file.
  • Click Go.

2. Removing WordPress comments from unregistered users

DELETE wp_comments, wp_commentmeta FROM wp_comments INNER JOIN wp_commentmeta 
WHERE wp_comments.comment_id=wp_commentmeta.comment_ID AND wp_comments.user_id = 0;
DELETE FROM wp_comments WHERE user_id = 0;

  • Click Go.

3. Remove all WordPress comments before a specific date

DELETE from wp_comments WHERE comment_date <= 'YYYY-MM-DD HH:mm:ss'

  • Update the command for your situation as follows:
    • YYYY is year
    • MM is month number
    • DD is the day
    • HH is the hour
    • mm is the minute
    • ss is the secondsIf you do not want to specify the time you can enter 00:00:00 for that part of the command. 
    • Warning: If your WordPress database uses custom table prefixes, then you must replace wp_ in each command with the prefix listed in your wp-config.php file.
  • Click Go.

4. Remove specific comments from WordPress database

  • Click on the wp_comments table.
  • Check the box next to each comment you want removed, or click the Check All box.
  • Click Delete
  • Click Yes

Further to know more about how to access database & run MySQL queries using phpMyAdmin, follow the previous post How to Manage MySQL Database with phpMyAdmin.

Thanks for visiting. For queries and suggestions, emails are welcome at learnweb@hostingcolumn.com.

Subscribe to Hosting Column for latest updates and posts.