Skip to content

Instantly share code, notes, and snippets.

@JoniWeiss
Created May 23, 2017 21:09
Show Gist options
  • Save JoniWeiss/798a1d64920c87671edf11fe86de288b to your computer and use it in GitHub Desktop.
Save JoniWeiss/798a1d64920c87671edf11fe86de288b to your computer and use it in GitHub Desktop.
WordPress: Replace URLs in the database when moving between servers
-- Run this to replace URLs in the database when moving a WordPress blog from
-- one URL to another.
-- Replace "wp_" with the table prefix you have chosen. (If it's "wp_" you
-- should really change it for added security).
-- 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.)
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