Last active
September 24, 2015 17:12
-
-
Save jamiehs/9647075 to your computer and use it in GitHub Desktop.
MySQL Find and replace for WordPress domain changing
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
# Table Prefix | |
SET @prefix = 'wp'; | |
# Find and replace strings | |
SET @find = "www.example.com"; | |
SET @replace = "www.example.dev"; | |
# Build and execute the statements | |
SET @sql1 = CONCAT('UPDATE ', @prefix, '_options SET option_value = REPLACE(option_value,?,?)'); | |
SET @sql2 = CONCAT('UPDATE ', @prefix, '_posts SET guid = REPLACE(guid,?,?)'); | |
PREPARE stmt1 FROM @sql1; | |
PREPARE stmt2 FROM @sql2; | |
EXECUTE stmt1 USING @find, @replace; | |
EXECUTE stmt2 USING @find, @replace; | |
DEALLOCATE PREPARE stmt1; | |
DEALLOCATE PREPARE stmt2; |
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
# Update wp_options table | |
UPDATE wp_options SET option_value = REPLACE(option_value,'www.example.dev','www.example.com'); | |
# Update wp_posts table | |
UPDATE wp_posts SET guid = REPLACE(guid,'www.example.dev','www.example.com'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment