All Collections
Useful Tools and Tips
WordPress: How to change Siteurl and Homeurl via MySQL cli (Requires SSH)
WordPress: How to change Siteurl and Homeurl via MySQL cli (Requires SSH)
Scott avatar
Written by Scott
Updated over a week ago

We can easily change the siteurl and homeurl via command line.
​ 

MySQL

For this we need to login to MySQL database. If we are not sure about the database details, check wp-config.php file. There we will get DB_NAME, DB_USER and DB_PASSWORD, which refers to our database name, database user and database user password respectively.

# grep DB /home/user/public_html/wp-config.php 
define('DB_NAME', 'ac******7');
define('DB_USER', 'ac******7');
define('DB_PASSWORD', '$password$');


Login to the database using the below command.

# mysql -u DB_USER –p 

Now it’ll be prompted for the password. Enter the DB_PASSWORD there.

In MySQL prompt we can select your WordPress database to update site and home urls.

MariaDB [(none)]> SHOW DATABASES; 
MariaDB [(none)]> USE DB_NAME;



The following command will display all the tables in your database.

MariaDB [DB_NAME]> SHOW TABLES;



We are going to make changes in the table ‘wp_options’ (name of wp_options table will be changed as per table_prefix)


The following command will display the current homeurl

MariaDB [DB_NAME]> SELECT * FROM wp_options WHERE option_name = 'home'; 


To change the homeurl:

MariaDB [DB_NAME]> UPDATE wp_options SET option_value="http://www.new_domainname.com" WHERE option_name = "home";



The following command will display the current siteurl

MariaDB [DB_NAME]> SELECT * FROM wp_options WHERE option_name = 'siteurl';


To update siteurl:

MariaDB [DB_NAME]> UPDATE wp_options SET option_value="http://www.new_domainname.com" WHERE option_name = "siteurl";

Did this answer your question?