Update WordPress URLS in Database by mysql command

When we shift a WordPress site to a new URL either live or to a production or development server, the new URL strings in the mysql database need to be changed and updated in the various mysql database tables.

With these method we can update 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.

1
2
3
4
5
6
7
UPDATE wp_options SET option_value = replace(option_value, 'http://www.devurl', 'http://www.liveurl') WHERE option_name = 'home' OR option_name = 'siteurl';

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

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

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

Finally update your WordPress config file “wp-config.php” should be in your web document root – change, databasename, username, password.

Leave a Reply