SQL for Rewriting WordPress Database Links

When you move a WordPress site, whether that’s from a live to a local site, or perhaps when you change the site to SSL, you will need to change the URLs in the database.

There are plugins for this, but it’s easy enough to do in the database itself using a few simple SQL statements in phpMyAdmin.

The three SQL statements you need are:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.example.com', 'http://www.new-example.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.example.com', 'http://www.new-example.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

Just change the URLs and then simulate the query to test it, then run it.


More Like This

Do you need someone to maintain your WordPress site?

Whether you’re looking for a monthly maintenance plan or occassional updates, we can help.