Moving WordPress — Useful SQL Queries & References

Don’t feel like typing all that SQL? Try this handy SQL generator for moving WordPress.

The following is my personal collection of useful SQL queries & references for moving WordPress.

WordPress Address (URL) & Site Address (URL)

Use the following SQL query to change the Site URL and Home URL in the wp_options table.

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

GUID

Use at your own risk! Please read this before executing the following query.

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

wp_posts

This query will fix all the internal links in the wp_posts table.

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

References

These articles in the WordPress Codex are also quite useful:

Leave a Reply

Your email address will not be published. Required fields are marked *