Import WordPress Database from Staging Server to Local Development Server

You may be working with a WordPress project and wish to use SVN to have a development instance, a staging instance, a local development instance and of course a production instance of the web site. This could prove to be problematic in keeping track of your data base instances. WordPress stores the root URL (http://website.com) at several places in their database. This can cause a problem when you try to import a copy of one of the live databases to your local development environment. When ever you click on a link it will send you to the live instance instead of remaining on your local environment. A way around this, for local development environment purposes, would be as follows:

  1. prior to importing the .sql file, open it in your favorite code editor. I like to use BB Edit.
  2. Perform a search and replace on the .sql file for the root url.
  3. ie:  search for “http://www.livestagingserver.com” and replace with “http://mylocaldev.me”
  4. Save the file and import it into your local WordPress data base.

Now whenever you click on your posts in your local development environment the links will stay within your local development environment.
This way, you can keep a local copy of your database so you have a faster and more local way of working. This also serves to keep the live instance of the database from getting contaminated with the residual artifacts of development work.

Leave a Reply

Your email address will not be published.