I migrated my blog from Drupal 5 to WordPress 2 nearly 2 weeks ago. The process wasn’t as painful as I thought it would be, thanks to a handy howto via vrypan.net. Another resource I refer to every time I get into tweaking MySQL rows is UrbanMainframe’s MySQL search and replace tipsheet. Thanks to both of these great resources for helping me through the migration.
This guide is intended only to document what I did. It’s not a polished howto or manual. There is no warranty. If you blow up your database because you didn’t work with offline backup copies, I won’t be able to help you. Actually, if you’re that silly, I won’t be willing to help you, either. Your mileage may vary.
Use a backup copy of your Drupal database, and a fresh WordPress database.
The basic process I followed was:
- Work from offline copies of the databases. Dump your Drupal 5 database, import it into a fresh database (say “
drupalmigration” or something creative). I did the migration on a separate machine from my “live” server – I used my desktop box, with local copies of MySQL and Apache. Anything with a decent version of MySQL on it will do.
- Install WordPress, (you don’t need to install Drupal for this migration) using the same database server containing the copy of your Drupal database (use “
wordpress” as the name of the new WordPress database).
- Now that you’ve got WordPress and Drupal running on the same database server, in separate databases, run this MySQL script which I modified slightly after the file provided by vrypan.net. The script assumes the WordPress database is called “
wordpress” and the Drupal database is called “
drupalmigration” – feel free to modify the script to match the database names you need to use, if they differ.
- That should do it. Log into your WordPress site. You might have to hand tweak the usernames, but all posts and comments should be there…
One additional thing I had to do was fix the
comment_ID values in the
wp_comments table. After migration, they were too big for the data type, and things went poopy. I’m sure there’s an elegant way to renumber rows in MySQL. I used brute force, by dumping the table to a .sql file and opening that in a text editor to do a search-and-replace to lower the numbers used as primary keys. I then moved the old table out of the way (renaming it to “
wp_comments_old“) and imported the new
wp_comments table definition and content. It was a funky thing to have to do, but it solved all kinds of comment-related misbehaviour.
Test things out in the migrated database. If all seems well, go ahead and dump the
wordpress database to a .sql file, and import it into a new database on your server. Install and configure WordPress on your server to use this new database. You may need to manually change the URL used by the blog, so that it matches the “live” server rather than whatever you used as a staging/migration server. The values are in the
wp_options table, with
option_name of “
siteurl” and “
home” – change those values to whatever matches the root URL for your blog.
You’ll also have to make sure all files are in the proper place, so URL references from the old Drupal content doesn’t point off to 404 error pages. That’s an exercise left to the reader. I just SSHed into my server and used a lot of
cp -R drupal/directoryname wordpress/directoryname – being paranoidally careful to copy files rather than just moving them. Always keep backups.
Update: I’ve updated the SQL script to automatically set the comment and category counts, so it should appear to work better now.