Change the WordPress domain after moving to a new host, using phpMyAdmin

After migrating your site to a new host, you might need to replace the site domain name.

You can do it before the site migration, as WordPress documentation suggest. Or you can do this with SQL query, directly changing the domain in the database. I prefer the last solution, I find it quick and easy

After you’ve done uploading your site’s directory and database, load the phpMyAdmin from your host.

Click on the main database first and then on the SQL tab.

SQL tab in phpMyAdmin

Use the SQL query shown below, past it inside the field.

Make sure to replace the database prefix wp_ to the one that matches your database.

Replace the http://www.oldurl with your old URL and http://www.newurl with your new URL

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');

For safety reasons, you may click on the Simulate Query button to preview the changes. If all is well, re-add the code and click on the Go button.

And that’s it! That simple 🙂

Let me know in the comments below if you have any other suggestions.

Leave a Reply

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