Move WordPress database to a new domain name or directory for free

If looking for a more thorough walk-through of moving files and databases from server to server, visit Migrating WordPress to a New Server.

In case you’re interested, you can also move between WordPress.com and WordPress.org.

Several years ago, I did a WordPress install at domain.com/blog and had a static homepage (i.e. not served up by WordPress). I’m not going to tell you that you should or shouldn’t do that. I’m going to tell you how to go from one to the other. For me, I moved WordPress from /blog to /.

But I was concerned about the database and my URLs. 2 key points:

  1. Below is a simple, 5 minute or less process to change the database references via search and replace.
  2. WordPress handles all the redirects automatically. It’s smart enough to know that domain.com/blog/my-favorite-post is now located at domain.com/my-favorite-post.

It’s Easy

Although it feels like a daunting task — changing from domain1.com to domain2.com, or changing from domain.com/blog to just domain.com, or from domain.net to domain.com — it’s very simple, quick, and easy.

One of the last reference links at the bottom of the Moving WordPress codex page is Search and Replace for WordPress Databases.

From that page, you can download the PHP script that works for MySQL databases (not just WordPress sites) without messing it up (i.e. it works, unlike search and replace in a text editor). Reference the changelog for learning the nitty-gritty details. For most applications, either version of the script — from the website’s download link or from the website’s GitHub link — will work just fine.

4 Simple Steps

All you have to do is follow the instructions. Here is a synopsis of the major steps:

  1. BACKUP FILES AND DATABASE. Then copy files from the old location to the new location (new server, new directory, whatever). If moving to a new server, it may take a while. If moving from one directory to another on the same server, it should take a much shorter time.
  2. Once the files are in the location you want them to be (maybe you didn’t move them at all because you’re just changing from domain1.com to domain2.com on the same server), upload the PHP script from interconnect/it to the same directory where wp-config.php is located. Then navigate to domain.com/name-of-the-script.php (this should take about 2 seconds)
  3. Follow the on-screen instructions (screenshots below) and enter your search-and-replace terms. For example, search for “domain1.com” and replace with “domain2.com”. Tip: Look in your database .sql exported backup file to see how your database is setup — should you search-and-replace with or without a trailing slash? — look for details like that. It’ll ask you to confirm your action, and once you click to proceed, it’ll be done in the blink of an eye. (all this should probably take about 1 minute)
  4. Delete the PHP script from your server. Don’t just rename it; delete it.

Following are screenshots for step #3, above:

Navigate to the script in your browser
Results of auto-importing the wp-config.php settings
Select all database tables
Enter the text to be replaced and the text to replace it with
View the results, maybe save a screenshot for your records

Again, make sure to delete the script after using it. Do not leave it up longer than the 2 minutes it takes to run it. If cannot complete the task immediately after uploading the PHP script, delete it from the server and re-upload it when you’re ready to run it because anyone that can access the file’s URL could run this script; it’s not password-protected.

I hope this quick tip saves you the error of your text editor Find and Replace ways and saves you the time and hassle of using another method. You could even say I just saved you $75+. If you feel inclined, you may donate at the PHP script’s download page.

Please share your experiences in the comment area below.

Featured Plugin - WordPress Google Maps Plugin

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Featured Plugin - WordPress Ecommerce Shopping Cart Plugin

Out of all the WordPress ecommerce plugins available, MarketPress has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Featured Plugin - WordPress Facebook Plugin

Would you like to add Facebook comments, registration, 'Like' buttons and autoposting to your WP site? Well, The Ultimate Facebook plugin has got that all covered!
Find out more

Featured Plugin - WordPress Infinite SEO Plugin

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
Find out more

Featured Plugin - WordPress Wiki Plugin

To get a wiki up and running you used to need to install Mediawiki and toil away for days configuring it... not any more! This plugin gives you *all* the functionality you want from a wiki, in WordPress!!!
Find out more

Featured Plugin - WordPress Q&A Site Plugin

It's now incredibly easy to start your own Q&A site using nothing more than WordPress - The Q&A plugin simply and brilliantly transforms any site, or page, into a perfect support or Q&A environment.
Find out more

Featured Plugin - WordPress Membership Site Plugin

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
Find out more

Featured Plugin - WordPress Pop-Up Chat Plugin

No javascript required, no third part chat engine, just fully featured chat right in your own database on your own WP sites - couldn't be easier.
Find out more

Featured Plugin - WordPress Appointments Plugin

Take, set and manage appointments and client bookings without having to leave WordPress. Appointments+ makes it easy.
Find out more

Comments (3)

    • Hi Neil. Thanks for asking. Yes, in terms of “how long the computer takes to find and replace all”, they’re both instant (or nearly so). The reason NOT to do a text editor search and replace on a MySQL database is because of serialized data. Read the first 2 paragraphs of the page where you can download the PHP script from. I hope this clears it up for you and saves you time/headache in the future. :-)

  1. First things first…why do you need a Domain name? Domain names are a human friendly version of a website address. Without a Domain name, you would be stuck with a load of numbers. Not great for marketing purposes.
    So we use Domain names to identify sites. When choosing your Domain name you should select a term people will use to search for your site. Most obviously, this could be your brand or personal name. Think about how you search on Google yourself. More info

Participate