Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MySQL Find and replace for WordPress domain changing
# 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;
# 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
You can’t perform that action at this time.