Migrate WordPress testing Site to production – Database update script

In case you change from staging site to live site, the site URL in the database is pointing to a different site URL value, this results in your website could not access. The below method shows you how to access the database and edit the record via the command line.

At first, you need to have access to the database via the command line, and at least you need to know your database username and password.

  1. login to your database instance
mysql -u username -p
  1. Switch to your database
show databases;
use wordpressdb;
  1. Change the value on table wp_options values of option_id 1 and 2
SELECT option_name, option_value FROM wp_options where option_id=1
SELECT option_name, option_value FROM wp_options where option_id=2
UPDATE wp_options SET option_value = replace(option_value, 'oldurl.com', 'newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'oldurl.com','newurl.com');
UPDATE wp_posts SET post_content = replace(post_content, 'oldurl.com', 'newurl.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'oldurl.com','newurl.com');

Update the values

UPDATE wp_options SET option_value = "http://yourstie.url" WHERE option_id=1
UPDATE wp_options SET option_value = "http://yourstie.url" WHERE option_id=2

after gaining access to the system, then use elementor > Tools > Replace URL to replace the old URL to the most updated one.

Leave a Reply

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