Forked from chuckreynolds/wordpress-change-domain-migration.sql
Last active
June 29, 2018 16:32
-
-
Save AshMartian/8fe32f4cf6689d8867680b5f149c1949 to your computer and use it in GitHub Desktop.
Use this SQL script when changing domains on a WordPress site. Whether you’re moving from an old domain to a new domain or you’re changing from a development domain to a production domain this will work. __STEP1: always backup your database. __STEP2: change the ‘oldsite.com’ and ‘newsite.com’ variables to your own. __STEP3: make sure your databa…
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
SET @oldsite='psd401.net'; | |
SET @newsite='lauri-dev.psd401.net'; | |
DROP PROCEDURE IF EXISTS setoptions; | |
DELIMITER $$; | |
CREATE PROCEDURE setoptions() | |
BEGIN | |
DECLARE done INT DEFAULT 0; | |
DECLARE site VARCHAR(255) DEFAULT NULL; | |
DECLARE cur CURSOR FOR SELECT table_name from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE "psd%options"; | |
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; | |
OPEN cur; | |
read_loop: LOOP | |
FETCH NEXT FROM cur INTO site; | |
IF done THEN | |
LEAVE read_loop; | |
END IF; | |
SELECT site; | |
SET @sql := CONCAT('UPDATE ', site, ' SET option_value = replace(option_value, ?, ?) WHERE option_name = "home" OR option_name = "siteurl"'); | |
PREPARE stmt FROM @sql; | |
EXECUTE stmt USING @oldsite, @newsite; | |
DEALLOCATE PREPARE stmt; | |
END LOOP; | |
CLOSE cur; | |
END; | |
UPDATE wp_blogs SET domain = replace(domain, @oldsite, @newsite); | |
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite); | |
UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite); | |
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite); | |
CALL setoptions(); | |
Added dynamic table updates for multisite options tables.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added wp_blogs for multisite