Last active
August 29, 2015 14:01
-
-
Save gustavorps/90c7566d652bbf794701 to your computer and use it in GitHub Desktop.
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
-- After migrating a WordPress site to a new URL either live or to a production or development server, | |
-- the new URL strings in the mysql database need to be changed and updated in the various mysql database tables. | |
-- This method just uses the whole mysql database rather than a WordPress export/import from within, | |
-- and is best suited for a straight swap. So you would copy all the WordPress files/folders to the | |
-- new destination, set the correct ownership to those files = then do the database switcheroo. | |
-- Do a mysql database export of the old database on the old server, create a new blank database | |
-- on the new server, import the old data either in phpmyadmin or mysql directly in the command line. | |
-- Make sure you have the new database selected, then run some sql updates and replacement commands | |
-- on the tables notably, wp_options, wp_posts, wp_postmeta. | |
-- Use the code as below and swap in your old and new URLs, no trailing slashes. Also if necessary | |
-- change the table prefix values where applicable (ie wp_ ) | |
UPDATE YOUR_PREFIX_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl'; | |
UPDATE YOUR_PREFIX_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl'); | |
UPDATE YOUR_PREFIX_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl'); | |
UPDATE YOUR_PREFIX_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment