Taking too long? Close loading screen.
Opening Up A New Dimension

How To Update URLs After WordPress Migration

Posted by: Herald Lynx Comments: 0 0 Post Date: May 26, 2016

How To Update URLs After WordPress Migration

This article covers updating URLs after WordPress migration without any plugin. After migrating a WordPress site to a new URL either live or to a production or development server. The new URL strings in the MySQL database needs to be changed and updated in the various MySQL database tables.

This method just uses the whole MySQL database rather than a WordPress export/import from within, and is best suited for a straight swap. So you would copy all the WordPress files/folders to the new destination, set the correct ownership to those files then do the database switcheroo.

WordPress Database Switcheroo

Do a MySQL database export of the old database on the old server. Create a new blank database on the new server. Import the old data either in phpmyadmin or mysql directly in the command line.
Make sure you have the new database selected, then run some sql updates and replacement commands on the tables notably, wp_options, wp_posts, wp_postmeta.
Use the code as below and swap in your old and new URLs, no trailing slashes. Also if necessary change the table prefix values where applicable (ie wp_ )

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

or via command line:

username@[~/Desktop]: mysql -u root -p databasename

Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 892
Server version: 5.5.13 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0

mysql> UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
Query OK, 0 rows affected (0.02 sec)
Rows matched: 964 Changed: 0 Warnings: 0

mysql> UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
Query OK, 0 rows affected (0.05 sec)
Rows matched: 964 Changed: 0 Warnings: 0

mysql> UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');g
Query OK, 0 rows affected (0.01 sec)
Rows matched: 686 Changed: 0 Warnings: 0

Finally update your WordPress config file to reflect the new database, “wp-config.php” should be in your web document root – change, databasename, username, password and host values:

define('DB_NAME', 'databasename');

/** MySQL database username */
define('DB_USER', 'username');

/** MySQL database password */
define('DB_PASSWORD', 'password');

/** MySQL hostname */
define('DB_HOST', 'localhost');

Now everything should link up perfectly.

djave has created a nice and easy script that takes the old and new URLs and hands you the SQL code for the WordPress swap, nice!

Serialized Data

Sometimes issues may arise with a problem called serialized data which is when an array of PHP data is somewhat like encrypted with the actual URL, so if the URL is changed the data is gone.
There are 3 brilliant tools that can handle serialized data and do a search and replace on the old and new databases for the URL and leave serialized data intact.

interconnectit

First up is a script you run via uploading it and browsing to it after migrating and importing your old database into the new – this will then make those necessary changes. Get it from here.

WP Migrate Pro

Second up is a plugin. You will need to install WP Migrate Pro on your original site. After installation use find & replace utility to change WordPress URLs. After changing a new database dump will be exported and that’s the one you need to import into the new URL hosted database.

Backup Buddy

Another option is to use Backup Buddy. You will need to install backup buddy after migration (if you don’t have it already). Go to Server tools > Database. Use the Mass URLs replace utility provided at the end of the page to update old links.

Note

Its important to note that WordPress database switchero, mentioned above, only updates links available in three default wordpress tables. Without any plugin your only option is to use database switchero. Without manual URL update you will not be able to access wp-admin.

Article By: Neil Gee

Share this post

Leave a Reply