Hart Associates - Advertising, Interactive, Public Relations, Video, Media » Our Five Favorite Lines of SQL

Blog

Our Five Favorite Lines of SQL

July 13th, 20090 Comments

Whenever we’re doing any WordPress development, we eventually have the need to sync the data between the current development server, possibly a staging server, and a live server. What’s the easiest way to move a WordPress database between two servers?

Let’s start this example by saying that we have two servers: Dev and Live. Each server has a mostly identical WordPress installation and each server has it’s own database. In order to sync the initial database from Dev to Live, the following steps may be used:

  • Use PHPMyAdmin to export the Development database as a file
  • Use PHPMyAdmin to export the Live database as a file (this is a backup, just in case)
  • Import the Development database into the Live database using PHPMyAdmin
  • Run the following five SQL commands in order to update the domain name in your site:
    UPDATE wp_multirss SET URL=REPLACE(URL,'Dev_Address','Live_Address');
    UPDATE wp_multirss SET Favicon=REPLACE(Favicon,'Dev_Address','Live_Address');
    UPDATE wp_posts SET post_content=REPLACE(post_content,'Dev_Address','Live_Address');
    UPDATE wp_posts SET guid=REPLACE(guid,'Dev_Address','Live_Address');
    UPDATE wp_options SET option_value=REPLACE(option_value,'Dev_Address','Live_Address');
  • And now, as long as you’ve written all your relative links correctly inside of your content, you’re finished!

Once you have the initial transfer completed, future transfers are much simpler. Then you only need to complete the above steps by exporting, dropping and importing the tables that are relevant to the changes that have been made. What tables are those? Honestly, it depends on what you have changed since the last time. The best way to figure this out is to go to the Database Description over at WordPress.org to see what you need to move.

Happy migrating!

Bookmark or share this:

Subscribe
  • Technorati
  • TwitThis
  • del.icio.us
  • Google Bookmarks
  • YahooBuzz
  • Xerpi
  • Digg
  • Reddit

Leave a Reply