Search and Replace MySQL using PHPMyAdmin

This is a life-saver: an easy way to search any table inside your database and replace one string of text with another. It works like a charm. But be careful, search first to see the results of your query before you commit the changes, and always backup prior to any database work.

Here is how you test the waters safely:

SELECT * FROM `wp_posts` WHERE `post_content` LIKE '%oops%'

Translation:

SELECT * FROM `table_name` WHERE `field_name` LIKE '%unwanted_text%'

And here is how you do some damage:

UPDATE `wp_posts` SET `post_content` = replace(post_content, 'oops', 'much better')

And translated:

UPDATE `table_name` SET `field_name` = replace(same_field_name, 'unwanted_text', 'wanted_text')

Tagged with:
 

5 Responses to Search and Replace MySQL using PHPMyAdmin

  1. great, this is what i’m looking for. thanks for sharing

  2. [n3rve] says:

    Thanks for sharing, exactly what I needed :D

  3. Thanks for this concise method for searching and replacing WordPress tables. After upgrading my WordPress structure from a subdirectory to the root domain, I had tons of 404′s and was dreading updating them by hand. Your code literally saved me days of work.

    Cheers mate.

  4. fubourius says:

    Thanks very good explained!

  5. Matt says:

    Thanks a lot for posting this! It saved me quite a bit of time–much appreciated!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">