As you probably already know, moving your WordPress blog to another domain or simply to another folder or subdomain in your own site is a little bit difficult because WordPress writes the full absolute path to your images, files and media directly inside the post body.
When you write a post and insert one image in it, WordPress will write the full path to that image, including your current domain, into the post’s HTML body. Assuming that you have your blog hosted on www.example.com domain, that means that in your post the image path will be “http://www.example.com/wp-content/uploads/image.jpg” (or something like that). If you want to move your blog to another domain, let’s say www.myblog.com, when you move the database, all of your previously written post will have the pictures with the old path, not the new one with the new domain name in it. Your only chance is to backup your database and manually edit all the post and change the absolute path to your images to the new domain. This, unless you do a full find and replace in your wp-posts table and set the new domain automatically.
This is done in the “wp-posts” table inside your MySql database.
How can you do this? It’s very simple in fact … Enter your website Cpanel and go to PhpMyAdmin (or your MySql manager of choice). Go to SQL query editing mode and use this line of code to do a full find & replace inside your posts:
update [TABLE] set [COLUMN] = replace([COLUMN], [OLD_VALUE], [NEW_VALUE]);
Assuming that you want to move your wordpress installation to the new domain like in the example above, the MySQL find and replace query should look like this:
update wp_posts set post_content= replace(post_content, “www.example.com”, “www.myblog.com”);
And run the query. Now all your old post should have the references to the images updated for the new domain.
Simple as that ! ![]()
Tags: MySQL, Online, Tips & Tricks, Web, Web development, Wordpress
Articole recomandate:
Comentarii Facebook:
2 Responses to “MySQL Find & Replace query”










Calin-Andrei Stan is a Photographer living in Romania. You can view some of his work on this photography blog. He writes about photography, technology, photo gear and software. His is a full-time Web Developer and his professional experience includes: Web development, E-mail marketing, E-commerce and Photography. 
I enjoy checking in daily to see your musings. I have your page bookmarked on my favorite read list!
Thank you for sharing this. Well done and very informative.