Today, I copied my blog to a local webserver - just for testing. And then I was in the need of changeing some basic information in the database. I had to change the siteurl of the blog, which is stored inside the mysql-database.
So, how can you change your site-url of the wordpress-blog by using mysql?
First log into your mysql-database
mysql -u user -p
After this have a look at all your databases:
mysql>show databases;
This may look somewhat like that:
+--------------------+
| Database |
+--------------------+
| information_schema |
| wordpress |
| mysql |
+--------------------+
Now, choose your database (in this case wordpress):
mysql>use wordpress;
After this, let’s have a look at the tables:
mysql>show tables;
The result looks like that.
+---------------------------+
| Tables_in_wordpress |
+---------------------------+
| wp_comments |
| wp_ec3_schedule |
| wp_links |
| wp_metar_cache |
| wp_now_reading |
| wp_now_reading_books2tags |
| wp_now_reading_meta |
| wp_now_reading_tags |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_terms |
| wp_usermeta |
| wp_users |
+---------------------------+
Most certainly, the needed information is stored in wp_options. So let’s have a more detailled look at this table:
mysql>describe wordpress_options;
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| option_id | bigint(20) | NO | PRI | NULL | auto_increment |
| blog_id | int(11) | NO | PRI | 0 | |
| option_name | varchar(64) | NO | PRI | | |
| option_value | longtext | NO | | | |
| autoload | varchar(20) | NO | | yes | |
+--------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
Now, we are searching for the right name inside the database.
mysql>select option_name from wordpress_options;
(Output is slightly abridged :-) )
+-----------------------------------------+
| option_name |
+-----------------------------------------+
| siteurl |
+-----------------------------------------+
OK, now let’s see, what is stored in this value…
mysql>select option_value from wp_options where option_name=’siteurl’;
+-----------------------------+
| option_value |
+-----------------------------+
| http://www.gimme-th.at/blog |
+-----------------------------+
1 row in set (0.00 sec)
So, the last task is to change the value to the new url.
mysql>update wp_option set option_value=’http://localhost/blog’ where option_name=’siteurl’;
And that’s it.