When managing a WordPress site, there are situations where you might need to change the Site URL and Home URL settings. These settings define the URL structure of your WordPress site and can impact how visitors access your website. While it's possible to adjust these settings via the WordPress dashboard, there are times when direct changes through the database or command line interface (CLI) may be more efficient or necessary—especially if you cannot access the admin panel or if you are migrating your site.
In this article, we will explore how to update the Site URL and Home URL both through MySQL queries and using WP-CLI commands, giving you flexible options to make these changes quickly and effectively.
Change Site URL & Home URL via WP-CLI
1:) Log in to your server via SSH:
#]ssh youruser@your-server-ip-address
2:) Navigate to the WordPress root directory:
#]cd /pathto/your/wordpress-installation.
Check the current Site URL and Home URL:
#]wp option get siteurl
#]wp option get home
3:) Update Site URL and Home URL
(Replace https://yourdomain.com with your actual new domain):
#]wp option update siteurl "https://yournewdomain.com"
#]wp option update home "https://yournewdomain.com"
4:) Check the updated Site URL and Home URL:
#]wp option get siteurl
#]wp option get home
5:) Search & Replace Old URLs in the Database (if needed)
#]wp search-replace "https://youroldsite.com" "https://yournewdomain.com" --skip-columns=guid
6:) Flush the cache by using below wp cli command
wp cache flush
Change Site URL & Home URL via MySQL/MariaDB-cli
1:) Log in to your server via SSH:
ssh youruser@your-server-ip-address
2:) Navigate to the WordPress root directory:
cd /pathto/your/wordpress-installation
3:) List the Wordpress database, username and password from wp-config.php
#] grep -i DB wp-config.php
define('DB_NAME', 'yourDatabaseName');
define('DB_USER', 'yourDatabaseUser');
define('DB_PASSWORD', 'yourPassword@');
4:) Execute following command to login MySQL/MariaDB console.
#] mysql -u yourDatabaseUser -p
This will ask for the database user password.
Once successfully logged into MySQL console.
5:) List databases in MySQL console
Mysql > SHOW DATABASES;
6:) Select the database
Mysql> USE yourDatabaseName;
7:) Execute following query to show the present siteurl and homeurl.
(Change the table name wp_options to the appropriate one”)
MySQL> SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl',
'home');
8:) Update site URL and home URL.
(Where yournewdomainname.com is new URL and Change the table name wp_options to the
appropriate one)
MySQL> UPDATE wp_options SET option_value = 'https://yournewdomain.com' WHERE
option_name = 'siteurl';
MySQL> UPDATE wp_options SET option_value = 'https://yournewdomain.com' WHERE
option_name = 'home';
9:) Verify the changes.
(Change the table name wp_options to the appropriate one”)
MySQL > SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl',
'home');
10:) Exit console
MySQL> Exit;
11:) Flush the cache by using below wp cli command
wp cache flush
Congratulations! You've successfully updated the Site URL and Home URL in WordPress using MySQL and WP-CLI.
If you have any questions, please don’t hesitate to contact our team via live chat.
For technical inquiries, please feel free to reach our support team by emailing support@bigscoots.com from your registered email or by submitting a support ticket.