WordPress change URL in database using MySQL Query

0

We are going to learn WordPress change URL in database using the MySQL UPDATE Query. This article will helpful for you when you want to move your site from one domain to another domain. When you change the WordPress site to a new domain. After that, You must change site URL in WordPress database For instance.

https://old-domain.com
https://new-domain.com

WordPress Change URL in Database using MySQL Query

MySQL provides the REPLACE function. Using that We can easily change the WordPress site URL to a new domain. I am going to share MySQL query with you. Using that you can easily update your WordPress site to a new domain.

Before sharing MySQL query with you. First of all, You should open PHPMYADMIN. PHPMYADMIN it’s required for executing MySQL query. If you don’t have access to the PHPMYADMIN then you can use PHP Adminer. You can access database using your MySQL username and password in PHP Adminer. Just upload the PHP Adminer file on your server and access it with your domain. PHP Adminer allow you to execute the MySQL query.

Change WordPress Site URL in database

Now, We are going to Change WordPress Site URL in the database using MySQL query. You Just need to copy the below query and change the domain names For example.

SET @search := "http://olddomain.com";
SET @replace := "http://newdomain.com";

UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "siteurl";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "home";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "product_list_url";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "shopping_cart_url";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "checkout_url";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "widget_text";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "headerImageLogo";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "cunjo_plugin_url";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "wpsr_socialbt_data";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "issuem";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "_transient_dgxdonate_t70pbg1htu_1396322372";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "dgx_donate_log";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "headerBackgroundImage";
UPDATE `wp_options` SET `option_value` = REPLACE(option_value, @search, @replace) WHERE option_name = "transact_url";
UPDATE `wp_postmeta` SET `meta_value`=REPLACE(meta_value, @search, @replace);
UPDATE `wp_usermeta` SET `meta_value`=REPLACE(meta_value, @search, @replace);
UPDATE `wp_posts` SET `guid`=REPLACE(guid, @search, @replace);
UPDATE `wp_posts` SET `post_content`=REPLACE(post_content, @search, @replace);

Copy the above all queries. Ther after, Replace the domain name from old to new for instance.

SET @search := "http://olddomain.com"; 
SET @replace := "http://newdomain.com";

After, Changing the domain name you should change the table prefix. In my case the table prefix id “wp_” So, I have added the table prefix with “wp_“. For example, Your table prefix is “tryvary_” then replace it with “wp_“.

change site url in wordpress database

How to change WordPress URL to https

Let’s see How to change WordPress URL to https. If you recently purchase the SSL Certificate for your Website. You implemented the SSL Certificate and You would like to change the WordPress URLs then just change your Query like

SET @search := "http://tryvary.com"; 
SET @replace := "https://tryvary.com";

Conclusion

Today, I have shared the information about How we can change WordPress URL in database when you move your site to the new domain name. Thanks for the reading this article and I hope this article is useful for you. Please write the comment if you face any kind of issue.

Share.

Leave A Reply

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