Migrate WordPress Website to New a Domain URL with MySQL / MariaDB

Want to move your current WordPress website to a new domain URL? For example, if you have a current WordPress website running on example.com and you want to migrate or move to a different domain like mynewexample.com, the steps below should help you…

This brief tutorial shows students and new users how to correctly move WordPress websites to a different domain URL and update is permalinks..

WordPress uses MySQL database to store all its data: posts, pages, profiles, configurations, links and more.. WordPress also uses Permalinks to link to pages, images, posts and other content in the database… These links are very important!

If these permalinks are wrong and pointing to incorrect data, your site is screwed!So, moving to a new domain should be handled with care.

If you have terminal access to your server and can run SQL commands, then steps below show you how to migrate WordPress websites to new domains URLs…

Step 1: Backup WordPress Content and Database

Before adjusting or migrating WordPress URLs and permalinks, your first task should be to back up WordPress current database..

You should always backup WordPress databases before making changes so that you can restore the database content if something goes wrong with the migration…

If you’re using MySQL or MariaDB as your database server, run the commands below to back up your database.

sudo mysqldump -u root -p wordpress_database_name > wordpress_database_name_backup.sql

The commands above will backup your current WordPress database and store it into a new file called wordpress_database_name_backup.sql

For more about backing up MySQL databases, read this post

Step 2: Switch WordPress URLs and Permalinks

Now that you have backed up your WordPress database, use the SQL commands below to switch or migrate WordPress URLs and Permalinks for all posts, pages, images and others…

Run the commands below to logon to the database server..

sudo mysql -u root -p

When prompted, type in the root password and logon…

After logging on, switch to the database you which to migrate by running the commands below.. For example, if your current WordPress database is named wp_database, use this command to switch to it:

use wp_database;

After switching, run the commands below to update or switch from the old URL to the new…

Update WordPress Site URLs with the SQL commands below:

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

Update WordPress (Globally Unique Identifier) GUID with the SQL commands below:

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

Update Post content with the SQL commands below:

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

Update WordPress Post meta with the SQL commands below:

UPDATE wp_postmeta SET meta_value = replace(meta_value,'oldurl.com','newurl.com');

The commands above will replace all references of the old domain with the new… and update all posts, metas and other data with the new domian URL…

When you’re done, exit and test your changes..

This post assumes that your current DNS system have records pointing to the WordPress server with the new domain name… If everything is done properly, your WordPress site should be resolving with its new domain name…

That’s it!

You may also like the post below:

Setup RainLoop Webmail on Ubuntu 16.04 / 18.04 with Nginx and PHP 7.2- Support

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.