The MySQL replace syntax is pretty simple to use. For example, let’s say using wordpress and you would like to replace all post titles with 2013-2014 to 2014-2015, you can simply use the following SQL syntax:
UPDATE wp_posts SET post_title = REPLACE(post_title,’2013-2014′,’2014-2015′)
More examples, such as searching and replacing text in the post_content column
UPDATE wp_posts SET post_content = REPLACE(post_content,”width:500px; height:500px;”,”width:740px; height:900px;”)
UPDATE wp_posts SET post_content = REPLACE(post_content,’text\’>www.’,’text\’>http://www.’)
Note that the REPLACE function performs a case-sensitive match when searching.
So let’s say post_title is “OLD POST title” and we would like to update that to “new post title”
This won’t work as there’s no exact match of “old post”
UPDATE wp_posts SET post_title = REPLACE(post_title,’old post’,’new post’)
Do this instead
UPDATE wp_posts SET post_title = REPLACE(post_title,’OLD POST’,’new post’)
Leave a Reply