Server

Change WordPress Site URL via Command Line MySQL

Here are quick steps to change your WordPress Site URL via the Command Line in MySQL. You might wanna use this approach because of reasons such as:

  • You’ve mistakenly changed the site URL to something horrible and site is broken so can’t use the WordPress Admin to change back to normal
  • You don’t know want to use the define('WP_HOME','http://domain.name'); define('WP_SITEURL','http://domain.name'); approach in the wp-config.php file which means when the WordPress admin is back, your Site URL and WP Home options will be grayed out.
  • You just love to use the command line.

If the above is you, then you should proceed by logging into your Droplet, if using DigitalOcean via SSH and let’s go via the terminal way:

Log into MySQL

$ mysql -u root -p

Enter your password and proceed to select our database of choice and list all tables in it

mysql> use wordpress;
mysql> show tables;

Next step is to update:

mysql> update wp_options set option_value = 'http://www.correctDomain.name' where option_id = 1;

Check to verify if changes were made:

mysql> select * from wp_options where option_value = 'http://www.correctDomain.name';

You’re done, and simply exit

mysql> \q

Make sure to disable any define('WP_HOME','http://domain.name'); define('WP_SITEURL','http://domain.name'); you have in your wp-config.php file then open up your website and visit your WordPress > Settings > General and you can now have a corrected WordPress website home and site URL.

Related Articles

Back to top button