Home > WordPress Tips and Tricks > Delete Hundred’s of database entries with one simple MySQL Query

Delete Hundred’s of database entries with one simple MySQL Query

Let’s say your website contat form did not have appropriate security on it or you weren’t using a Capthca and it got hit with an automated SPAM attack. You could end up with hundreds if not thousands of worthless database entries that should probably be cleared out. This is especially true if you fear that some malicious code might have been injected into that particular database table.

You clearly don’t want to have to delete these entries one row at a time. That would take forever. The easiest thing to do is log into your phpMyAdmin account, select the appropriate database and then go to the database table affected. Next, click on the “SQL” tab which will load the “Run SQL query/queries on database” field.

I will generally use the SELECT function first to just verify that the rows I am selecting for final deletion is actually correct. Below is an example query. You would just have to change “wp_cformsdata” for the table name that you are using and “f_id” for the ¬†field identifier¬†you were using.

ex. SELECT * FROM `wp_cformsdata` WHERE `f_id` BETWEEN 551 AND 19294;

Also Please, Please, Please make a backup of your database first. Deleting hundreds of rows within a table can produce unexpected results if you are not careful.

Once you have backed everything up and you have verified which rows you want to delete you can use the below SQL query.

ex. DELETE FROM `wp_cformsdata` WHERE `f_id` BETWEEN 551 AND 19294;

Good luck and happy blogging!

WordPress Tips and Tricks

  1. No comments yet.
  1. No trackbacks yet.