in MySQL

Migrating a WordPress database between domains

Occassionally I find myself developing a WordPress theme which will then require moving from development into production or otherwise having to move a blog between domains.

Apart from the transfer of the files, including plugins, theme and core WordPress installation, there is only 1 slightly gotcha: the database. I’ve never been quite sure why but WordPress stores the URL of the blog in it’s database, not once, but twice. For the blog to be migrated the database needs a slight tweak.

As always, create a backup before doing anything. This can be done with phpMyAdmin or using the mysqldump command like so:

$ mysqldump -uUSER -pPASSWORD DATABASE > /path/to/backup.sql

If the database is to be hosted on a different machine you can then import this dump using using which ever method you’re comfortable with. Finally, run the following query on the database, substituting your own domain name:

UPDATE
	wp_options
SET
	option_value = 'http://DOMAIN.TLD'
WHERE
	option_name IN ('siteurl', 'home');

That’s it!

Write a Comment

Comment

  1. Be careful – if you’re hosting the blog from a subdirectory (as I do with mine) then siteurl will be “http://DOMAIN.TLD/SUBDIR”.

    For example, http://sickbiscuit.com/blog

    I usually just update these options by hand when I need to, which isn’t all that often.

  2. Cheers John! I’ve updated the post accordingly.

    This is something I had to do a number of times last year and I found myself going back over my notes each occasion…