Manually change WordPress’ home and siteurl in MySQL

       296 words, 2 minutes

In my tidy process, I had to copy WordPress from one host to another, then access it from various URLs so that the production and the development versions were both accessible from the same public IP. To duplicate the data in a fast manner, I dumped the SQL data and tarred the WWW directory. The problem is that WordPress’ home and siteurl are kept the same between those instances. And since you try to access the administration zone, you’re redirected to the original location… To modify the duplicated instance, you can configure WordPress straight from MySQL.

Here are the directions:

# mysql -u wpuser -p wpbase
mysql> SELECT * FROM options WHERE option_name = 'siteurl' OR option_name = 'home';
+-----------+---------+-------------+--------------------------+----------+
| option_id | blog_id | option_name | option_value             | autoload |
+-----------+---------+-------------+--------------------------+----------+
|        37 |       0 | home        | http://www.tumfatig.net/ | yes      |
|         1 |       0 | siteurl     | http://www.tumfatig.net/ | yes      |
+-----------+---------+-------------+--------------------------+----------+
2 rows in set (0.00 sec)

mysql> UPDATE options SET option_value = "http://test.tld:8080/" WHERE option_id = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> UPDATE options SET option_value = "http://test.tld:8080/" WHERE option_id = 37;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM options WHERE option_name = 'siteurl' OR option_name = 'home';
+-----------+---------+-------------+-----------------------+----------+
| option_id | blog_id | option_name | option_value          | autoload |
+-----------+---------+-------------+-----------------------+----------+
|        37 |       0 | home        | http://test.tld:8080/ | yes      |
|         1 |       0 | siteurl     | http://test.tld:8080/ | yes      |
+-----------+---------+-------------+-----------------------+----------+
2 rows in set (0.01 sec)

mysql> QUIT
Bye

The duplicate copy is know manageable from http://test.tld:8080/ when the production is still available from http://www.tumfatig.net/.

Quite simple ; when you know what to modify and how.