Skip to content

Instantly share code, notes, and snippets.

@abackstrom
Created November 18, 2011 22:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abackstrom/1377901 to your computer and use it in GitHub Desktop.
Save abackstrom/1377901 to your computer and use it in GitHub Desktop.
Update WordPress Network URLs
UPDATE wp_blogs SET domain = 'www.example.dev';
UPDATE wp_site SET domain = REPLACE(domain, 'example.com', 'example.dev');
UPDATE wp_sitemeta SET meta_value = REPLACE(meta_value, 'example.com', 'example.dev') WHERE meta_key = 'siteurl';
UPDATE wp_domain_mapping SET meta_value = REPLACE(meta_value, 'example.com', 'example.dev');
DROP PROCEDURE IF EXISTS wploop;
DELIMITER $$
CREATE PROCEDURE wploop()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE tname VARCHAR(20);
DECLARE selsql VARCHAR(200);
DECLARE opttables CURSOR FOR select table_name from information_schema.tables where table_schema = 'wordpress' and table_name like 'wp\_%\_options';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN opttables;
optloop: LOOP
FETCH opttables INTO tname;
IF done THEN
LEAVE optloop;
END IF;
SET @selsql = concat("UPDATE ", tname, " SET option_value = REPLACE(option_value, 'example.com', 'example.dev') WHERE option_name IN ('siteurl', 'fileupload_url', 'home');");
prepare selsql from @selsql;
execute selsql;
END LOOP;
CLOSE opttables;
END;$$
DELIMITER ;
CALL wploop();
DROP PROCEDURE IF EXISTS wploop;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment