How to change a WordPress site’s SiteURL and HomeURL via command line?
Yeah, MySQL commands are ready to help you with SiteURL and HomeURL!
It’s not a big task to change SiteURL and Home of a WordPress website via command line. If you love black always prefer commandline than web-interface :p Most of the Sysadmins would like to use command line. Hence I’m explaining here about it. We know how to reset WordPress users password via command line.
To change SiteURL and Home we need to log into the MySQL database. If you’re not sure about the database details you can gather information about it in wp-config.php file. There you’ll get DB_NAME, DB_USER and DB_PASSWORD which refers to your database name, database user and database user password. Now you can log into MySQL database via command line.
# mysql -u DB_USER -p
Now you’ll be prompted for the password. Enter the DB_PASSWORD there.
Now you’re in MySQL prompt. There you can select your WordPress database to update siteURL and home.
SHOW DATABASES; USE DB_NAME;
Now you’re in your database. The following command will display all the tables in your database.
SELECT option_name FROM wp_options;
This command will display all the columns in wp_options table. The following command will list out the option name “home” from wp_options table.
SELECT * FROM wp_options WHERE option_name = 'home';
The following command is to update the new value for “home”
UPDATE wp_options SET option_value="http://www.your_newhost.com/" WHERE option_name = "home";
Next is to list and update the option name “siteurl” from wp_options table.
This command will list current site URL from wp_options table and the next command will update the current site URL.
SELECT * FROM wp_options WHERE option_name = 'siteurl';
To update siteurl
UPDATE wp_options SET option_value="http://www.yourn__ewhost.com/" WHERE option_name = "siteurl";
Now everything will work as your expectation. That’s it 🙂