How to Update WordPress Site URL and Home URL via Command Line?

It’s very easy to update the WordPress site’s site URL and home URL via phpMyAdmin from control panels like Cpanel and Plesk. What to do if the WordPress hosted sites doesn’t have a control panel. The only way is to update the site URL and home URL via command line. For that, we need to login to the Mysql Database.

We will get the MySQL database information like DB_NAME, DB_USER, and DB_PASSWORD from the WordPress configuration file wp-config.php.

* MySQL settings – You can get this info from your web host

** The name of the database for WordPress *

define(‘DB_NAME’, ‘jigote_wp261’);

** MySQL database username *

define(‘DB_USER’, ‘jigote_wp261’)

** MySQL database password *

define(‘DB_PASSWORD’, ’26)PS9e0.9′);

Login to the server and let us see how we can login to the Mysql database prompt via command line.

#mysql -u DB_USER -p

Enter the DB_PASSWORD password.

[root@admin /]# mysql -u jigote_wp261 -p

Enter password:

Now we are in Mysql Command prompt. Enter the SHOW DATABASES command to view your database.

mysql> SHOW DATABASES;
+——————–+
| Database |
+——————–+
| information_schema |
| jigote_wp261 |
+——————–+
2 rows in set (0.08 sec)

With the help of USE DB_NAME command. We can select the database jigote_wp261 to update the home URL and site URL.

mysql> USE DB_NAME;

mysql> USE jigote_wp261;

Database changed

Now we are in the database ( jigote_wp261). To view all the tables of the database, use the command

SHOW TABLES;

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

SELECT option_name FROM wp_options;

Update Home URL >>

Let’s check what is the current home URL from the command line. The following command will list the option name “home” from the wp_options table.

mysql> SELECT * FROM wp_options WHERE option_name = ‘home’;

+———–+————-+———————–+———-+
| option_id | option_name | option_value | autoload |
+———–+————-+———————–+———-+
| 36 | home | http:// www. webiste_name. com | yes |
+———–+————-+———————–+———-+
1 row in set (0.00 sec)

How to update the home URL using the UPDATE command. Enter the new site URL option_value””

UPDATE wp_options SET option_value=”http://www.new_webiste_name.com/” WHERE option_name = “home”;

Update Site URL >>
To view, the current site URL use the following command.

mysql> SELECT * FROM wp_options WHERE option_name = ‘siteurl’;

+———–+————-+———————–+———-+
| option_id | option_name | option_value | autoload |
+———–+————-+———————–+———-+
| 1 | siteurl | http:// www. webiste_name. com | yes |
+———–+————-+———————–+———-+
1 row in set (0.00 sec)

How to update the site URL using the UPDATE command.

wp_options SET option_value=”http://www.new_webiste_name.com/” WHERE option_name = “siteurl”;

Now the home URL and site URL are updated. It is very easy to do and mainly used to change the URL’s, adding https, add/remove www and etc.