Change The WordPress Site URL, Using Command-Line
Nowadays, everyone is familiar with WordPress domains. As WordPress uses the MYSQL database to store the data which includes its site and home URLs too. Sometimes, we also need to change the WordPress site URL in the database.
For Example – When we are doing the migration of WordPress sites from one server to another server, we have to change the old WordPress Site URL in the MySQL database to the new one.
You can add the site URL and home of WordPress using the wp-config.php file. As it is relevant to change the site URL in the database.
Follow the steps to change the WordPress Site URL in the database using CLI
If you want to find your WordPress domain’s database details from the wp-config.php file.
You can find this file in the document root of your domain.
Follow the given steps to change the WordPress URLs including the WordPress site URL in the MySQL database.
1. Log in to the Mysql prompt.
mysql -u root -p
2. You need to select your WordPress Database
mysql > show databases;
mysql > use wordpress_db;
3. Change the WordPress URLs in the database using the following command line:
MariaDB [wordpress_db]> UPDATE wp_options SET option_value = replace(option_value, ‘https://old_wordpress_url’, ‘https://new_wordpress_url’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
MariaDB [wordpress_db]> UPDATE wp_posts SET guid = replace(guid, ‘https://old_wordpress_url’,’https://new_wordpress_url’);
MariaDB [wordpress_db]> UPDATE wp_posts SET post_content = replace(post_content, ‘https://old_wordpress_url’, ‘https://new_wordpress_url’);
MariaDB [wordpress_db]> UPDATE wp_postmeta SET meta_value = replace(meta_value,’https://old_wordpress_url’,’https://new_wordpress_url’);
4. Now, replace the old_wordpress_url and new_wordpress_url with your WordPress URLs.
Now, you are able to access the WordPress site using the new updated URL.
If you want to change the home and site URL of WordPress using the wp_options table through the PhpMyAdmin.
Was this article helpful to you? If you continue to have problems with the outlined above, please contact the eTechSupport Team.
December 12, 2022
November 24, 2022
October 21, 2022