Database Migration - Drupal to Wordpress

Visited 1344 times | Submited on 2007-07-28 00:21:44

*Note: This post is culled from an earlier post at one of my other blogs. Also note that this is targeted towards people with at least a minimal, but preferably an intermediate to advanced knowledge of MySQL databases and phpMyAdmin, thus the category Advanced.

Sooner or later if you are running a Blog or Content Management System (CMS), you will find yourself wanting to switch platforms. With the proliferation of blogging and CMS platforms out there, it seems almost inevitable that you will find yourself experimenting with one system and then deciding that another may be better suited for your needs. Here, I’m focus on migrating to Wordpress, one of the more popular, open source platforms.

The good news is that Wordpress is easy to install (the five-minute install is a claim to fame). The even better news is that Worpress supports importing posts from a variety of platforms and online services: Textpattern, DotClear, Movable Type, Typepad, LiveJournal, Blogger (unfortunately right now only the old Blogger; the new Blogger is not supported yet), GreyMatter, and Blogware, as well as from RSS feeds are all currently supported by Wordpress’ import engine.

The bad news is that popular CMS platforms Drupal and Joomla are not currently supported. So what to do if you want to move from Joomla or Drupal to Wordpress (with Wordpress’ recent moves towards behaving more like a CMS, I predict we’ll see more people wanting to do this)?

Since I recently had to move a Drupal powered site to Wordpress, I thought I’d share the experience here (a Joomla database migration may or may not be similar; you attempt to follow this guide for a Joomla site at your own risk. I wouldn’t recommend it).

(Please note: database migration is always a risky business. Please be sure to back up everything before attempting to migrate your database. Myself and the SDN will not be held accountable if you destroy your site and can’t restore it.)

So, for anyone interested, here’s how I did it (This documents a migration from Drupal 4.7 to Wordpress 2.04).

First, I installed Wordpress in a temporary folder and backed up the Drupal databases (again, this is most important thing you can do). If you don’t know how to do this, stop here and go no further. The main thing to do afterwards is to move all of the information from the Drupal database to the Wordpress database. You need to put the Drupal database tables that you will be grabbing information from into the Wordpess database. I did this by exporting the tables from the Drupal database and then importing them into the Wordpress database. It’s the easiest way I have found to do it, but there are other ways to do this if you’re willing to spend a lot of time with Google. I then ran the following queries on the Wordpress database:

First remove the info from the WP databases

DELETE FROM weblog_wp_categories ;
DELETE FROM weblog_wp_posts ;
DELETE FROM weblog_wp_post2cat ;
DELETE FROM weblog_wp_comments ;

Insert the users from the Drupal installation (I had to remove the ID and UID fields that were suggested by others to avoid a “duplicate entry error”)

INSERT INTO wp_users
(user_login, user_pass, user_nicename, user_email, user_registered)
SELECT
name, pass, name, mail, FROM_UNIXTIME(timestamp)
FROM users;

Move the categories

INSERT into 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;

Move the posts (Note that with Drupal 4.7, the post body and other information is no longer held in “Node,” but “Node_Revisions.”)

INSERT INTO wp_posts(
ID, post_author, post_date, post_content, post_title, post_excerpt,
post_name, post_modified
)
SELECT nid, 1, FROM_UNIXTIME(timestamp), body, title, teaser, concat('OLD',nid), FROM_UNIXTIME(timestamp)
FROM node_revisions

Recreate the relationships between the posts and the categories

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

Insert the comments

INSERT INTO wp_comments (
comment_post_ID, comment_date, comment_content, comment_parent
)
SELECT nid, FROM_UNIXTIME(timestamp), concat(subject,' ', comment), thread
FROM comments ;

Get rid of the tables that you imported earlier

DROP TABLE term_data;
DROP TABLE term_hierarchy;
DROP TABLE node;
DROP TABLE term_node;
DROP TABLE comments;
DROP TABLE users;

This is the most basic method that I started out with. I found myself going back and adding more table fields when I discovered that I could get more information to transfer. There were also a few weird glitches that I encountered later (some of the text in the comments appeared twice). Anyone that tries this will also have to make slight adjustments depending on how their databases are set up and the versions of Drupal and Wordpress that you are working with.

Of course, the final step is to move your new Wordpress installation to the main folder you keep your blog in and make the necessary linkage adjustments.

By Kevin



Add your comment

Name:(required)
E-mail address:(optional)
Comment:(required)
Repeat the number for validation: (required)

Browse by Tags:


Text Link Ads

Statistics

Total 296 articles submitted
Latest submission at January 28, 2008 15:13

Feedback

Use this email below to send us your suggestions and feedback. We value your opinion.
info (at) theitarticles.com