A MySQL query to find & replace text in your database

| No Comments »

Problem: Help! I need to replace some words with something else in my database.

Solution: Use the replace() function to do a search and replace query.

UPDATE table_name SET table_field=REPLACE(table_field,"old_text","new_text");

Here’s an example:

UPDATE wp_posts SET post_content=REPLACE(post_content,"localhost","www.cybervaldez.com");

Easy as pie!



Leave a Reply