Migrating from Drupal to Wordpress

blogging — Tags: — Panayotis @ 12:03

I finally decided to move my greek blog from drupal to wordpress. Since there was no migration script, I wrote a couple of sql statements that moved all posts, comments and categories from my drupal tables to the (new) wordpress 1.5 tables.

Here is the proccess in short:

WARNING!!! This may delete your DATA!!! Make sure you backup EVERYTHING before starting the procedure!!!

1. setup a fresh wordpress installation.
2. make sure term_data term_hierarchy node term_node comments (drupal tables) are in the same DB you use from WP.
3. Run the following SQL statements:
delete from weblog_wp_categories ;
delete from weblog_wp_posts;
delete from weblog_wp_post2cat ;
delete from weblog_wp_comments ;

insert into weblog_wp_categories(cat_ID,cat_name, category_nicename, category_description, category_parent) select term_data.tid, name, name, description, parent from term_data, term_hierarchy where term_data.tid=term_hierarchy.tid ;

INSERT INTO weblog_wp_posts(
ID, post_date, post_content, post_title, post_excerpt, post_name, post_modified
)
SELECT nid, FROM_UNIXTIME(created), body, title, teaser, concat('OLD',nid), FROM_UNIXTIME(changed) FROM node WHERE type='blog' OR type='page' ;

INSERT INTO weblog_wp_post2cat (post_id,category_id) SELECT nid,tid FROM term_node ;

INSERT INTO weblog_wp_comments (
comment_post_ID, comment_date, comment_content, comment_parent
)
SELECT nid, FROM_UNIXTIME(timestamp), concat('',subject, '<br />', comment), thread FROM comments ;

You should now have all your posts and comments and categories in WP. Go to the admin interface and make sure everything is in place…

Notes: This is not the perfect way to migrate. Comments are not nested in the right way. A lot of things may not work. On the other hand if, like me, made a really simple use of Drupal, this should move most of your data to WP…

18 Comments »

  1. You can modify the comment part of the SQL statements so that the commenter’s name, email and home page are retained instead of entering each as anonymous. Change to this:

    INSERT INTO wp_comments (
    comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_content, comment_parent
    )

    SELECT nid, name, mail, homepage, FROM_UNIXTIME(timestamp), concat(’‘,subject, ‘
    ‘, comment), thread FROM comments ;

    Comment by Michael — 2005-03-17 @ 05:03
  2. I KISS YOU!

    Absolutely wonderful, works flawlessly (well, ok, after I poke thing to allow for the fact that I have more than one database, and that I didn’t want the ‘page’ nodes imported. But wow, lovely. Thank you.

    Comment by Tom Insam — 2005-03-17 @ 05:03
  3. Migration from Drupal to WordPress complete
    Well, I finally made the move and migrated the site from Drupal to WordPress. I finished everything up yesterday and I’m now only finding some time to write about how the process went. I saw some commentary and references to the ideas I placed forth i…

    Trackback by Tom Markiewicz — 2005-03-29 @ 07:03
  4. I’m trying to decide between Drupal and WordPress right now for blogging. Why are you converting to WordPress? Why is it better than the older Drupal? I’d really like to know! Thank you.

    Comment by ryan — 2005-04-06 @ 11:04
  5. Very, very cool. Thanks for posting this, my friend. If you’re ever in Ann Arbor, MI, look me up and I’ll buy you a beer, or several beers.

    Comment by Dan Romanchik — 2005-05-06 @ 20:05
  6. Thanks very much for publishing this. It saved me hours of time trying to figure out how to do this on my own. In my case, the Drupal blog was running out of a different database than the WP blog, so I had to create the Drupal post table (I hadn’t been categorizing the posts), but that was simple enough to do.

    Thanks again! Dan

    Comment by Dan Romanchik — 2005-05-07 @ 05:05
  7. Thanks very much for this. I’m in the process of testing a migration from Drupal to Xoops where I’ll be using the WP plugin. Posts and categories went through with no problem. Comments import are throwing sql errors, so I’ve got a bit of figuring to do yet.

    Comment by Herb — 2005-05-12 @ 19:05
  8. Migrating from Drupal to Wordpress-把Drupal转换为Wordpress
    WordPress没有从Drupal转换到WordPress的程序,还是看看别人是怎么做的吧~学习学习
    [提醒]切记,要先备份啊!!
    I finally decided to move my greek blog from drupal to WordPress. Since there was no migration script, I …

    Trackback by 冰古Blog — 2005-05-26 @ 07:05
  9. Mal wieder alles anders

    Nach einem halben Jahr mit drupal bin ich gestern wieder auf Wordpress umgestiegen. Einer der Gründe: Ich brauche für meine private Seite, die eigentlich doch nur ein Weblog sein soll, kein Community-System.
    Der Umstieg ging mit kleineren Problemche…

    Trackback by rifter.org — 2005-08-12 @ 16:08
  10. Here’s a cleaned up and more complete set of queries. My drupal database is called “blog” and my wordpress database is called “wordpress”. Also, I’m at -0800 to GMT.

    –Wipe out existing content
    DELETE FROM wordpress.categories;
    DELETE FROM wordpress.posts;
    DELETE FROM wordpress.post2cat;
    DELETE FROM wordpress.comments;
    DELETE FROM wordpress.users
    WHERE ID > 1;

    –Copy users
    INSERT INTO wordpress.users (ID, user_login, user_pass, user_nicename,
    user_email, user_registered, display_name)
    SELECT uid, name, pass, name, mail, FROM_UNIXTIME(created), name
    FROM blog.users
    WHERE uid > 1;

    –Copy over categories
    INSERT INTO wordpress.categories
    (cat_ID, cat_name, category_nicename, category_parent, category_count)
    SELECT term_data.tid, name, name, parent, count(term_node.tid)
    FROM blog.term_data
    INNER JOIN blog.term_hierarchy ON (term_data.tid=term_hierarchy.tid)
    LEFT JOIN blog.term_node ON (term_node.tid = term_data.tid)
    GROUP BY term_data.tid

    –Copy over all the blog posts, pages and forum topics
    –All will be posts in wordpress
    INSERT INTO wordpress.posts
    (ID, post_author, post_date, post_date_gmt,
    post_content, post_title, post_excerpt, post_status, comment_status,
    ping_status, post_name, post_modified, post_modified_gmt)
    SELECT nid, uid, FROM_UNIXTIME(created), FROM_UNIXTIME(created + (60*60*8)),
    body, title, teaser, ‘publish’, ‘open’, ‘closed’,
    concat(’node-’,nid),
    FROM_UNIXTIME(changed), FROM_UNIXTIME(changed + (60*60*8))
    FROM blog.node
    WHERE type IN (’blog’, ‘page’, ‘forum’);

    –Copy the post to category
    INSERT INTO wordpress.post2cat (post_id, category_id)
    SELECT nid,tid
    FROM blog.term_node ;

    –Copy the comments and associate them with the top level blog post (threading lost)
    INSERT INTO wordpress.comments
    (comment_ID, comment_post_ID, comment_date, comment_date_gmt, comment_content, comment_approved, comment_parent)
    SELECT cid, nid, FROM_UNIXTIME(timestamp), FROM_UNIXTIME(timestamp + (60*60*8)),
    concat(”, subject, ”, comment), 1, CONVERT(thread, UNSIGNED)
    FROM blog.comments;

    Comment by Leon Atkinson — 2006-03-11 @ 04:03
  11. ALWAYS GRATEFUL!

    You saved me literally hours and hours of gruelling, repetitious work. Your work does not go unnoticed!

    Comment by Jim Brown — 2006-05-09 @ 04:05
  12. It worked like a charm, except for the comment count part.

    Please use this

    UPDATE wp_posts, node_comment_statistics SET wp_posts.comment_count = node_comment_statistics.comment_count WHERE wp_posts.ID=node_comment_statistics.nid;

    Cheers

    Comment by JPierre — 2006-05-16 @ 00:05
  13. I rewrote some SQL lines in my blog (click my name) so that this will work for Drupal 4.7. I decided to convert as well.

    Comment by Dave Dash — 2006-05-20 @ 05:05
  14. […] I found a handful of sites that documented their migration from Drupal to Wordpress and I want to give them props for helping me get along my way: Tom Markiewicz, miscellaneous factZ, Vrypan|Net|Log, and Spindrop were all great resources. Props. […]

  15. […] So, I’m just in the process of converting the site, which has been made significantly easier using the post I found on vrypan.net. […]

  16. […] 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 […]

  17. […] a few weeks ago and detailed it all on his blog. He made generous use of Panayotis’s detailed instructions, so it was actually a group effort. The SQL applied surprisingly cleanly, though I found that all […]

  18. […] for help with the migration and i truly found a few sites — keyboardsamurais.de, vrypan.net and Tom Markiewicz — to be very helpful.  (THANK YOU!) however, as much of a help they were […]

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2008 vrypan|net|log | powered by WordPress with Barecity