Migrating a WordPress site to new url or domain, live or to a production/development server, new URL strings in the mySql database need to be changed and updated in various database tables.

This method is work when you like to move whole mysql database via phpmyadmin instead export/import all within wordpress admin. So you would copy/move all wordpress files/folder to new destination, set the correct ownership to those files and than start work on database.

Old url to New url change within phpmyadmin

  1. Export database from old server.
  2. Create a new blank database on New Server
  3. Import old database via phpmyadmin import wizard
  4. Use the code as below in sql query and change in your old and new URLs, no trailing slashes.

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old.url', 'http://www.new.url') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.old.url','http://www.new.url');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old.url', 'http://www.new.url');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.old.url','http://www.new.url');

replace old url to new url

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

define('DB_NAME', ‘dbname');
/** MySQL database username */
define('DB_USER', 'username');
/** MySQL database password */ d
efine('DB_PASSWORD', 'password');
/** MySQL hostname */
define('DB_HOST', 'localhost');

Now everything should be fine.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.