How to migrate from Drupal 5 to WordPress 2

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:

  1. 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.
  2. 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).
  3. 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.
  4. 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.

75 thoughts on “How to migrate from Drupal 5 to WordPress 2”

  1. 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.

  2. @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.

  3. 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

  4. 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. :)

  5. 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!

  6. 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!

  7. 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.

    1. D,

      I’ve heard the “right tool for the right job” comment a number of times, and all I have to say in return is, you’ll have to convince me (and I’ve seen no one, who seems to have a real argument).

      The way I see it– moving from Drupal to WordPress is like moving from a Saturn to a Yugo. Except that it’s worse.

      Yes, Drupal is not auto-configured to be a blogging platform– and perhaps there would be some value, in having a “blogging release” for Drupal. However, — it’s just not that hard. What, specifically, do you get from WP that you don’t get in Drupal (given that the WP backend is quite a bit better in UI/usability, versus D5?). My feeling is– once you’re stuck in WP– it’s like a Friday night in Des Moines– the limits (user accounts; comments; etc) are so great, you don’t even know what you’re missing.

      Under the hood– under the hood, WP is just a hacked mess with no architectural consistency. Drupal’s modular architecture, with a hooks/callback system, as well as active community review in a central archive– all of this seems to me miles ahead of the WP system, where hundreds of contributors maintain hacks/modules that adhere to no coding standards, community or otherwise.

      If you want to have anything or do anything in and with WordPress, other than a rather plain vanilla “blog” of posts, one after another… well good luck. And if you think “a blog is all I want,” well, you should get out of Des Moines.

      1. Way to ignore how the two apps work. I’ve lived in both for years now. I’m not some punk kid farting around with blogging, getting frustrated, and running to Blogspot or something. I’ve spent a fair bit of time actually doing this stuff.

        They are different – both subtly and not so subtly. WordPress rocks for blogging. Drupal rocks for websites. There is overlap, but that’s where there strengths are.

        and I’ve never been to Des Moines.

        1. Well, I see you have a quick temper there. I have to wonder if you have an argument to go with it. Next thing I know, you’ll tell me how you programmed on the VAX.

          WordPress seems OK for blogging– if your idea of blogging is something like, “write posts that are nothing but a spew of my own opinion,” and “have people leave random comments.” Fine. (It also has some nice AJAX UI features). But as soon as you want to do anything else– say, work collectively with multiple authors, or present materials in another or more complex fashion- using WordPress is like hitting a brick wall. If you actually need to do anything else, say for business reasons, then you’re rather stuck.

          Of course, like the social scene in Des Moines, (the phrase is “nothing as dead as a Friday night in Des Moines,”), there’s more to the world than blogging with WP. (Of course, like the residents of Des Moines, many bloggers have no idea!). WordPress, like Des Moines, tends to enforce its own narrow boundaries and narrow-minded self-satisfaction with what one has.

          I guess from the above, that you call “everything else” a “website.” (I though a blog was a website, last I checked in the dictionary). But whatever. Your attitude speaks for itself (“I ain’t some kid…”). Once again, if you have something more to say, some detail, other than the old “best tool for the job,” with no concrete, detailed substantiation of why and when and in what situation WP is better…

          1. Hey Ken, I heard Drupal is really good for coming soon placeholders on your “website.” Fine work, seems like you are putting all those fancy Drupal features to the test :)

          2. I’m not sure how you saw a quick temper there. All I was trying to say is that the post wasn’t because of some rash or half-baked opinion, that I’ve used both apps in depth for years. That is all.

            I’m not going to debate definitions of blogging. That’s as pointless as feeding trolls.

            By “website” (above), I was meaning something like “complicated, department- or institution- level web presences, managed by teams of people, and extended to provide functionality that is used to actually run an organization.” Drupal rocks at that. I use it all the time for that.

            But, for a smaller scale, simple publishing setup, wordpress just makes more sense. To me. Yes, I know wordpress can do much more than simple blogging (just as drupal can do much more than “websites”).

            Maybe I’ll book a trip to Iowa to see what the fuss is about.

          3. D,

            How fast can you get some kind of properly threaded comments in here (I can’t even tell what “reply” I’m supposed to hit, so I’m hitting the nearest one).

            I understand your argument, and I’m saying, I see it all the time and I’m just not sure it’s true. Yeah, sure, WordPress looks slick and sweet– especially if you’re just starting out. It’s sort of like a Porsche body, with a Honda engine inside.

            My counterpoints, then:

            1) I’ve never seen this argument expanded, in much detail. Cite a use case; make the argument.

            2) I tend to think that WP (along with being rather underpowered and poorly made) tends to limit horizons. Have I used WP? Sure– and I dislike it every time. (You just can’t do threaded comments “right”– without a lot of effort, for instance, though the newest WP has a much better version… if, and only if, you have a theme that hasn’t hacked away at the comments layer).

            Drupal isn’t perfect, but most of this is solved “out of the box.”

            1. Looks like that may be a bug, either in the theme or WP’s comment threading. Annoying. It happens.

              I’m not going to try to sell wordpress. you’ve tried it, and it doesn’t work for you. that’s fine – use a tool you’re comfortable with.

              Really, it comes down to what you’re comfortable with. Neither is perfect. Neither is complete. They don’t have to be. Either app can be convinced to do nearly anything, with little or no code hacking involved. That’s the beauty of it.

        2. Hey Jim,

          Just cleared the DB on that site and started again– am actually using it, as the base for a WP to Drupal conversion (thus you find me here).

          What would you like me to show you? (I’ve worked on about 100 Drupal sites in the past 18 months). http://dev.flamingorecordings.com/ is one of my favorites– part of a multisite install– lots of media & customization options, though I think the standard forums are kind of lame (client had some budget limitations).

          Cheers,

          Ken

  8. 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…

  9. 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)

  10. 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

  11. 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?

  12. Hi , I’d like to migrate my old drupal 5 gallery content to my WordPress gallery (which is actually a WP Blog with images/videos as seperate posts).any tips i should follow?thanks!

  13. While I have not done this for WP 2.5.1 directly, I don’t think the changes to the SQL script would be that hard to make. I may look at it later, but I still have more work to do on the site I needed to convert from Drupal 5 to WordPress.

    I installed WP 2.2, then made some changes to the SQL script, because the site I’m converting has many contributors, and on my first conversion attempt, this script didn’t do anything to import users, no names, no logins, no passwords. I had to add that info into the SQL script.

    Another mod I had to make was to accomodate how database users are handled in Plesk. There’s no easy way to give a single mysql user access to multiple databases in Plesk, and the workaround requires root and/or shell access. It was easier for me to do a mysqldump of the Drupal database and import everything into my new WP database… none of the table names overlapped, so that seemed to be the simple and obvious workaround.

    So I imported the Drupal db tables into my WP db, then changed the script to not refer to external databases, and the script ran like a charm. It brought my users over, kept their same passwords, and their ownership of various articles. Once that was done, I upgraded WP from 2.2 to 2.5.1, and now the new site is running just fine, and all it needs is some cleanup to work in my new template.

    Once I finish some more individual tweaking to take advantage of the new magazine-style WordPress template I’m using, I’ll just drop the Drupal tables from my WP db, and be done with it.

    I may take another look at the SQL script later, because there is one other Drupal site that needs to be converted, and I’d like to avoid the “instal WP 2.2 / Upgrade to WP 2.5″ step, if I can.

  14. I too am looking for a way to migrate a Drupal 5.3 installation into WordPress 2.5.1 or 2.6 depending on timing. I have yet to come across anything that would make this remotely feasible to do on my own. No scripts or anything to move to a newer version of WordPress.

    So this comment is for you Dnorman. I write for a big named website who has been using drupal since 2005 and we now want to move to WordPress but are finding ourselves facing a huge brick wall. It looks like you have experience migrating things over between drupal and WordPress and I’d like to know if you would talk to me off of the blog either through email or skype about a possible project for you or at least, explain what is possible and what is not possible in terms of migration.

    Looking forward to hearing from you.

  15. 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…

  16. Anyone know if this works for Drupal 5 to current version of WP? Am also wondering if anyone has had problems migrating content due to Drupal modules (I’m using a blog module for posts).

  17. Hi, I’m trying to use this script for Drupal 5 to WP 2.6.3 and I got the following error:

    crida SQL:

    DELETE FROM wp_categories;

    MySQL diu:

    1146 – Table ‘MYDB_wordpress.wp_categories’ doesn’t exist

    I guess the same will happen with the wp_post2cat table referenced in the script.

    Could anyone provide some assistance in adapting the script to WP2.6.3?

    Thanks!

  18. The SQL script doesn’t seem to work with WordPress 2.6, like AlbertC mentioned above. It also doesn’t convert Drupal node revisions. (WordPress supports post revisions since version 2.6.)

  19. A few months ago I updated this script and migrated my site from Drupal 5.9 to WP 2.6. My inelegant hack of D’Arcy’s excellent script worked, but I couldn’t get the categories to transfer properly, so I just did those manually. Posts and comments came across fine, though. If you’re facing a similar transition and don’t mind that limitation, feel free to try my version (http://dovdox.com/content/archives/135). Standard disclaimers apply.

  20. It depends. It could take a few minutes, with an updated version of the script, or it could take days. And is your name really “Drupal Hosting”? They do have some odd names in Belgium. Sadly, your comment smells a bit spammy.

  21. The SQL script doesn’t seem to work with WordPress 2.6, like AlbertC mentioned above. It also doesn’t convert Drupal node revisions. (WordPress supports post revisions since version 2.6.)

  22. Thanks for the script! I managed to transfer most of my posts and comments from my old drupal 5 site to wordpress effortlessly. I had neglected my drupal site mostly because of it’s clunkiness, it feels as if I take a lot of time to do very simple things.

  23. The SQL script doesn’t seem to work with WordPress 2.7, like AlbertC mentioned above. It also doesn’t convert Drupal node revisions. (WordPress supports post revisions since version 2.7.)

  24. Thanks for the script! I managed to transfer most of my posts and comments from my old drupal 5 site to wordpress effortlessly. I had neglected my drupal site mostly because of it’s clunkiness, it feels as if I take a lot of time to do very simple things.

  25. 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.

    1. the instructions are now quite out of date – they might get you pointed in the right direction, but will need tweaking to work with current versions of Drupal and WordPress…

  26. Great tutorial. But my url’s didn’t come along cleanly. Special characters remain in the slug, so you get this/kind/of/url or this-;-kind. Pretty odd.

    Does anyone know of a way to clean up all these url’s? The location of the bad url’s in the WP database is the post_name field in wp_posts. I could use a query to replace all special characters with a dash, but that doesn’t ensure the same link structure as in Drupal.

    What I could also do is a query to fill the post_name field with the url’s from the Drupal database. The ID’s of the article would be the reference as to what url would come where.

    Does anyone have a query that would point me into the right direction? Would be eternally grateful!

Comments are closed.


The spammers win. I've disabled comments. Again. It's just not worth having to deworm my site from the inane autospam jabber that trickles through the spam filters. Sorry. I can be contacted via the Contact form here on the site, or out on the internets (I'm @dlnorman on twittar).

BUT I WANT TO POST A COMMENT HERE. WITNESS THE OPPRESSION INHERENT IN THE SYSTEM.

If you need to post a response, trackbacks are enabled and will be displayed normally.

The Trackback URL for this post is:
http://darcynorman.net/2007/05/15/how-to-migrate-from-drupal-5-to-wordpress-2/trackback/