• Skip to primary navigation
  • Skip to main content
  • Skip to footer

JH Tech Services

A knowledgebase

  • Portfolio
  • Knowledgebase
  • About

SQL commands after moving WordPress database backup to new site

June 20, 2013 by jer0dh

UPDATE 2019:

if wp-cli is installed this process can be much easier.
First you can backup the database in case you have a typo.


wp db export

This will create a sql file.

Now lets replace the domain everywhere in the database.


wp search-replace "http://sourcedomain.com/" "http://destdomain.com/" 

if you want to do a dry run and see what tables would be updated without the option ‘–dry-run’ and not update the guid’s of the posts


wp search-replace "http://sourcedomain.com/" "http://destdomain.com/" --dry-run --skip-columns=guid

Run the command with ‘–dry-run’ and that should update everything even serialized string data. One exception to this is properties in a serialized object.

If you needed to restore the original sql database


wp db import 

I backup a development site to a SQL file and using phpAdmin, I can restore it to another developement site or production site. Once that is done, this can fix the links and such.

Did discover that this will not fix any links that are set in the text of Widgets. All widget text is stored in a single field under wp_options where option_name = “widget_text”

UPDATE wp_posts
SET guid = REPLACE(guid,'http://sourcedomain.com/','http://destdomain.com/');

UPDATE wp_posts
SET post_content = REPLACE(post_content,'http://sourcedomain.com/','http://destdomain.com/');

UPDATE wp_options SET option_value = 'http://destdomain.com'
where option_name='siteurl';

UPDATE wp_options SET option_value = 'http://destdomain.com'
where option_name='home';
  • Knowledgebase
  • Wordpress

Footer

  • Portfolio
  • Knowledgebase
  • About

© 2023