We are all familiar with how to change the WordPress home and siteurl through WordPress Admin page. If you are not, you can read about it [here]. Also, you can override the WordPress settings by specifying the home/siteurl in the wp-config file. You can see how to do this [here].

In this tutorial, you will learn how to change the siteurl specified in WordPress database using MySQL command line method. So let’s start fresh. Assuming you are not sure of the password/database associated with the blog, follow any of the below steps to get the database credentials of the database associated with the blog

1: If you have SSH access to the account, navigate to the document root of the blog and issue the following command.

2: If you have cPanel or any control panel access, login to your account and through the FileManager application, open the wp-config.php file in the document root of the blog and note the entries against the DB_NAME, DB_USER, and DB_PASSWORD.

3: If none of the above is available, then you can FTP to your account and download the wp-config.php file locally and open it to view the fields.

Now that you have the database credentials, the next step is to connect to the database. In this case, the database is on the same server itself as can be seen from the DB_HOST field. If you have SSH Access to your account, issue the following command to connect to your database.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

If you are connecting to the database remotely then use the following format.

mysql -u database-user -p database_name -h server_name

It is necessary to whitelist the IP you are connecting from in cPanel >> RemoteMySQL if you are on a cPanel server and sometimes also through the server depending upon the host configuration. If you find trouble connecting, contact your host for exact instructions to sort it out. You can find the IP you are connecting from by visiting whatsmyip

Now that you have logged in, let’s look at how to get the home/siteurl changed.

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

SHOW TABLES;

This below command will display all the columns in wp_options table.

SELECT option_name FROM wp_options;

The following command will list out the option name “home” from wp_options table.

SELECT * FROM wp_options WHERE option_name = ‘home’;

To change the value for ‘home’, issue the following command. Remember to change the http://www.newwebsite.com/ field as the website name to be assigned. Also, remember to keep the trailing slash ‘/’