Change And Update WordPress URL In Database When Website Moved To New Hosting

Change And Update WordPress URL In Database When Website Moved To New Hosting

Table of contents



After migrating WordPress based website to new URL, either from localhost to hosting server or from old hosting or to new hosting with a domain name different, the URL string in the MySQL database needs to be changed and updated in the various MySQL database tables of the wordpress installation.

 

This method will use update function on MySQL database, so changing some values ​​from database table instead of using export / import WordPress feature from within dashboard and most suitable for direct migration. So you would copy all WordPress files/folders to a new destination, set the correct ownership for those files, then do a database switcher.



 

First, export MySQL database from the old database on the old server, create a new empty database on the new server, import the old data via PHPMyAdmin.

 

Make sure you've selected the new database, then run some SQL updates and replace commands on the table, especially wp_options, wp_posts, wp_postmeta.

 

Use the code as below and replace the old URL with your new URL, without the trailing slash. Also if necessary, change the table prefix value if applied (i.e. wp_)

 

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

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

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

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

 

Finally, update your WordPress configuration file to match the new database settings, wp-config.php ” which should be in your web document root - change: database, username, password and host value.

define('DB_NAME', 'newdatabasename');

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

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

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

 

Now everything is perfectly connected. I'm used to doing the above manually, if anyone knows a good wordpress plugin to backup and move it to another server, you can suggest it in the comments column. 

 

If you need website development services - Bali Web Design, you can contact me via contact page. I am a Bali Web Programmer and Web Developer with experience since 2011. I can create and maintenance websites based on PHP, Wordpress CMS and Codeigniter Framework.



Artikel Terkait