Home » WordPress » How to Change the WordPress URLs in MySQL Database?

How to Change the WordPress URLs in MySQL Database?

If you need to change the URLs of your WordPress site, when domain change or moving from old server to new server, you can make the necessary changes directly in the database.

bellow these SQL Queries you can run in new environment to change the WordPress URLs. Please replace oldurl.com and newurl.com

UPDATE options SET option_value = REPLACE(option_value, 'https://oldurl.com', 'https://newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE posts SET post_content = REPLACE (post_content, 'https://oldurl.com', 'https://newurl.com');
UPDATE posts SET post_excerpt = REPLACE (post_excerpt, 'https://oldurl.com', 'https://newurl.com');
UPDATE postmeta SET meta_value = REPLACE (meta_value, 'https://oldurl.com','https://newurl.com');
UPDATE termmeta SET meta_value = REPLACE (meta_value, 'https://oldurl.com','https://newurl.com');
UPDATE comments SET comment_content = REPLACE (comment_content, 'https://oldurl.com', 'https://newurl.com');
UPDATE comments SET comment_author_url = REPLACE (comment_author_url, 'https://oldurl.com','https://newurl.com');
UPDATE posts SET guid = REPLACE (guid, 'https://oldurl.com', 'https://newurl.com') WHERE post_type = 'attachment';

You can follow this article to if you do this using Command line interface
https://webhostinggeeks.com/howto/how-to-change-the-wordpress-urls-in-mysql-database/

And this Article help you to do it using phpMyAdmin
https://wpbeaches.com/updating-wordpress-mysql-database-after-moving-to-a-new-url/

using this simple tool you can generate these queries 

https://rudrastyh.com/sql-queries-to-change-wordpress-website-domain

Duminda Wijerathna

An all round web designer building websites Over 18 years. Interested in achieving a suitable placement in the field of IT in a growth oriented organization which offers diverse job responsibilities in order to utilize and improve my skills, Knowledge and experience.

Leave a Comment

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