What is the mysql command to delete all rows with a certain string? Print

  • mysql, string, row, query, delete, remove, bulk, quarry
  • 300

The magic query to delete a row based on your custom settings is:

delete from [table name] where [column name] like '%[text to find]%'

You'll need to understand how this works to change the variables.

delete - means to delete a row

[table name] - this is the table you want to search in

[column name] - this is the column you want to search in

%[text to find]% - this field needs the % characters on either side of the keyword to search for all strings with that word in it.

In this working example, spammers added thousands of users with a blog name in the username. We went into phpmyadmin and ran a quarry to remove them all with this code:

delete from wp_users where user_login like '%blogname%'

 


Was this answer helpful?

« Back