Skip to main content
null 💻 notes

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,
  "", "");

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:

will turn into this:

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.