Jesse Lawson

Software engineering, artificial intelligence, writing, and open-source tools

Jan 1, 0001 - MySQL Tutorials WordPress

How to Find and Replace a String in MySQL

One of the problems with moving your site from one domain to another is that the images in all your posts are still served from the old setup. In order to fix this, you need to run a simple MySQL command that will search through all your posts and replace the old URL with the new one.

The first thing you want to do is login to your phpMyAdmin, or get to the point where you can run SQL commands on your database. Once there, issue the following command:

update wp_posts set post_content = replace(post_content, "old.linkstructure.com", "mynewlinkstructure.com");

What this does is update your wp_posts  table by setting every instance of post_content  to the value of post_content with the link structures swapped out. Run this and every post that links to an image with a URL like this:

http://old.linkstructure.com/wp-content/uploads/2013/01/01/mydog.jpg

will turn into this:

http://old.linkstructure.com/wp-content/uploads/2013/01/01/mydog.jpg

If you have a unique situation or are having troubles, let me know in the comments below and let’s see what we can do.