Created
January 23, 2018 06:28
-
-
Save wzul/ee7330f13d03c92cd1d1557f10e4cde0 to your computer and use it in GitHub Desktop.
SQL to replace URLs in the WordPress database when moving between servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Run this to replace URLs in the database when moving a WordPress blog from one URL to another. | |
-- | |
-- Replace "wp_" with the table prefix if you have changed it. | |
-- | |
-- You may need to update other tables/columns as well - I normally use phpMyAdmin's database search tool to search for the old URL. | |
-- | |
-- Note: Don't replace the guid field if you're changing the URL of a live site, only if you're making a development site live.) | |
-- | |
-- Alternatively, use WP-CLI (http://wp-cli.org/) or WP Migrate DB (https://en-gb.wordpress.org/plugins/wp-migrate-db/) | |
UPDATE wp_posts | |
SET post_content = REPLACE(post_content, "http://www.old.com", "http://www.new.com"), | |
guid = REPLACE(guid, "http://www.old.com", "http://www.new.com"); | |
UPDATE wp_comments | |
SET comment_author_url = REPLACE(comment_author_url, "http://www.old.com", "http://www.new.com"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment