Skip to content

Instantly share code, notes, and snippets.

@chrisdigital
Last active October 11, 2015 14:48
Show Gist options
  • Save chrisdigital/3875245 to your computer and use it in GitHub Desktop.
Save chrisdigital/3875245 to your computer and use it in GitHub Desktop.
Find and replace string in MYPHPAdmin in Wordpress SQL tables
Wordpress global find and replace in SQL
//Source: Global Find and Replace In Wordpress using MySQL | Barry Wise NJ SEO and Marketing Consultant
//http://www.barrywise.com/2009/02/global-find-and-replace-in-wordpress-using-mysql/
//http://stackoverflow.com/questions/7548964/sql-find-and-replace-text
//http://stackoverflow.com/questions/421227/sql-to-search-and-replace-in-mysql
//http://tdot-blog.com/wordpress/6-simple-steps-to-change-your-table-prefix-in-wordpress
UPDATE wp_posts SET post_content = REPLACE(post_content, 'staging.server.com', 'www.productionserver.com');
UPDATE [your_table_name] SET [your_table_field] = REPLACE([your_table_field], '[string_to_find]'
@chrisdigital
Copy link
Author

//This code proves more updated and efficient
//http://wordpress.stackexchange.com/questions/16777/change-site-url-when-moving-site-to-another-url
//http://wordpress.stackexchange.com/questions/7693/what-sql-query-to-do-a-simple-find-and-replace
//This Post above also includes a link to a walkthrough of myPHPadmin edits ( http://tdot-blog.com/wordpress/6-simple-steps-to-change-your-table-prefix-in-wordpress )

UPDATE wp_options SET option_value = replace(option_value, 'staging.server.com', 'www.productionserver.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'staging.server.com','www.productionserver.com');

UPDATE wp_posts SET post_content = replace(post_content, 'staging.server.com', 'www.productionserver.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value, 'staging.server.com', 'www.productionserver.com');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment