How to migrate from Drupal 5 to WordPress 2
Posted by: dnorman in general, tags: drupal, howto, mysqlI 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.







Entries (RSS)
May 15th, 2007 at 10:25 pm
This one is Digg worthy;)
May 15th, 2007 at 11:09 pm
just wait for the WordPress-to-Drupal re-migration process to be documented…
May 16th, 2007 at 1:19 pm
Great stuff, just what I need
I really need to move dslrblog over to wordpress, drupal is hindering rather than helping me over there 
May 28th, 2007 at 12:32 am
Thanks, this works pretty well, only one problem. On the main page it says “no comments” even for posts that have comments. How would you fix that.
May 28th, 2007 at 8:22 am
Ibrahim: That’s related to WordPress’ caching of the comment count for each post as a field on the wp_posts table so it doesn’t have to count the comments each time it displays the count.
I believe I ran the SQL from here:
http://www.brendanloy.com/2007/02/wordpress-21-upgrade-problems.html
I should add that as the last step of the migration script…
May 28th, 2007 at 8:27 am
OK. Updated the .sql script. It should now properly update both comment count and category count cache values.
June 6th, 2007 at 7:11 pm
[...] real key was the script I found on D’Arcy Norman’s blog. D’Arcy did the migration a few weeks ago and detailed it all on his blog. He made generous [...]
July 4th, 2007 at 4:44 am
[...] My friend Damian and I have just been moving DSLRBlog from Drupal 5 to WordPress 2 using instructions from D’Arcy Norman. [...]
July 4th, 2007 at 6:29 pm
When I submitted a comment I ended up at http://www.darcynorman.net/wp-comments-post.php which is a http 404.
July 4th, 2007 at 6:34 pm
Hmm, worked here. The post I was commenting on was http://www.darcynorman.net/2007/07/03/macosx-vs-ubuntu/ .
Also the a href’s to full size images in http://www.darcynorman.net/2006/09/06/dells-media-pc-is-twice-as-expensive-as-an-imac/ 404 .
Hope that helps.
July 4th, 2007 at 8:39 pm
@Lloyd: Looks like my spam blocker decided not to like you for some reason. Sorry! I’ve rescued your comment on the Ubuntu post. I have no idea why it bumped you to wp-comments-post.php with a 404 error, though. Bizarre… Sorry about that.
August 5th, 2007 at 9:36 pm
Hello darcy. I’m enhancing and unifying some other migration scripts, and putting a tutorial together along the way. the final detail to resolve is permalinks. With drupal I had my “clean URLs” with underscores from the root of my URL e.g. site.com/article_is_here. I can update Wordpress config to work in this fashion using the first link, but I can’t get permalinks to work using the info at the second link. In your case you said you did a lot of copying. Could you expand on that a bit or suggest the best way to avoid 404s for all my existing Google cache? Thanks!
http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
http://codex.wordpress.org/Using_Permalinks
August 6th, 2007 at 1:14 pm
Hello. I found this reference on URL rewriting and it seems to have enough examples for me to apply to my situation. If you have any other good ones, please drop me a line. Thanks.
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html
October 1st, 2007 at 8:29 am
[...] assist with the moving everything back I had a search about on the web and found a simple guide here. The conversion script worked perfectly, and I was up and running in under half an hour. A quick [...]
October 9th, 2007 at 5:31 pm
Hi there! I had some trouble when trying to use this script on my Drupal 5 blog (currently) to WordPress 2.3. When I tried to use the script, this error kept popping up: “#1146 - Table ‘wordpress.wp_categories’ doesn’t exist”. And it is correct. I am assuming this is because I am using the latest version of WordPress, which is V.2.3.
I will try installing WordPress V.2 and see what happens! I will keep you updated.
October 9th, 2007 at 11:54 pm
Whew! After some tweaking here and there (mostly because of my hosting - it had nothing to do with your wonderful script!), I finally got it to work. You saved me an incredible amount of time. Thank you so much!
October 10th, 2007 at 5:19 pm
[...] and did the unthinkable; I migrated my blog from Drupal to WordPress. I found a great resource, over at D’Arcy Norman dot net, that helped me immensely with copying over the tables, etc. to the new [...]
October 12th, 2007 at 10:02 am
one should note - this works splendidly up to wordpress 2.2, but in 2.3 they seem to have done away with “categories” and now have a “term” and “taxonomy” structure. this means that if you follow all these steps with a wordpress 2.3 database, you get everything except categories assigned properly. (you’ll get the same error that Binary Blonde got, above — this script tries to delete from a table, then insert into a table, that doesn’t exist)
an easy solution is to instead install wordpress 2.2, import your data, then upgrade wordpress 2.2 to 2.3. if you cannot do that (my host has a “one click install” for 2.3) what i did instead was make my 2.3 database *look* like a 2.2 database again, import the data, then use wordpress’ wp-admin/upgrade.php page to move the database from 2.2 to 2.3.
even with this fiddling, you saved me oodles and oodles of time. thanks!
October 25th, 2007 at 2:26 am
[...] 参考文章以及作者提供的SQL转换代码:How to migrate from Drupal 5 to WordPress 2 [...]
November 6th, 2007 at 11:38 pm
Hello, I’m curious as to why established Drupallers are opting for WP? I’m guessing its a usability improvement (n.b. Drupal did win this year’s Packt CMS award http://www.packtpub.com/award) ?
November 7th, 2007 at 9:42 am
Drew, it’s not a comment on the quality of Drupal - I use it on nearly every project I work on - but just that it makes sense to choose the right tool for the job. Drupal _can_ do blogging properly, if you spend some time configuring and tweaking it. WordPress _can_ do websites, if you spend some time tweaking. But, if you use each tool for the tasks they excel at, you’ll wind up with Drupal powering high-end dynamic websites, and WordPress running a blog. They’re both awesome bundles of code, but they are best applied in their own respective areas of focus.
January 28th, 2008 at 7:09 am
[...] http://www.darcynorman.net/2007/05/15/how-to-migrate-from-drupal-5-to-wordpress-2/ [...]
March 5th, 2008 at 7:59 am
[...] assist with the moving everything back I had a search about on the web and found a simple guide here. The conversion script worked perfectly, and I was up and running in under half an hour. A quick [...]
March 11th, 2008 at 7:28 pm
Thanks a lot for the MySQL Sheet. I was doing the reverse process (Wordpress to Drupal) and I couldn’t solve the node types. A simple database replacement and -woooo - it runs. Things could be so easy…
March 18th, 2008 at 5:35 am
[...] last night and managed to transfer all of the data in a couple hours of work. The key was this sql script to transfer everything, which is a little bit old and required installing Wordpress 2.0, importing, [...]
March 23rd, 2008 at 12:42 am
I think the database files are the most important point on moving to wordpress. Thanks for the useful tips.
April 5th, 2008 at 2:35 am
Thanks for making this page
My Conversion is Drupal 5.2 to WP wordpress-2.0.4 old version downloaded only for conversion.
the script works good except…..
If you have many categories in Drupal like
Government
- State - state names
and
Business - State Names
It will choke a bit and shoot everything into uncatagorized
AND for people that use CCK and Address Fields
that content is not stored in the normal area of content
So if like me you have lots of businesses listed on pages using special CCK fields
The script will make the page blank and you will have to manualy copy the info
All in all though you saved me a MRI and Brain Aneurysm :o)
April 7th, 2008 at 4:58 pm
[...] http://www.darcynorman.net/2007/05/15/how-to-migrate-from-drupal-5-to-wo... Fantastic Drupal to Wordpress migration post with an SQL script that works quite well. You need to migrate to Wordpress 2.0 for it to work. [...]
April 11th, 2008 at 7:07 pm
Thanks for this guide it really helped in the migration process with our corporate blog. We had a little bit of hangups in the process but overall it was a great success! I’m bookmarking this page if I ever need it again ~ Cheers Jason
May 5th, 2008 at 12:27 am
Has anyone yet modified this for a Drupal5->WP 2.5.x Migration? This should be quite different due to the new term-stuff in WP?
May 11th, 2008 at 8:18 am
@Frank
I am looking for a solution for this too.