Migrating Drupal to Wordpress
October 10th, 2005
Here are some scripts along with instructions for migrating a drupal site to wordpress.
README.txt
These instructions are ‘implemented’ in code as a small python script called migrate-drupal-data.py which you can find below.
Dump your drupal database. To find out how to do this refer to the manual for your db (for mysql from the command line you use mysqldump and for postgres it is pg_dump)
Load the drupal dump into your wordpress db:
mysql -u [username] -p [password] < [path-to-drupal-dump]Edit the convert-drupal-data.sql script replacing ‘weblog_’ with your wordpress prefix
Run convert-drupal-data.sql script against your wordpress db:
mysql -u [username] -p [password] < convert-drupal-data.sqlWARNING: this will delete all existing posts, comments and categories from your wordpress db. If you don’t want to do that edit the script as indicated therein).
Finished.
Scripts
convert-drupal-data.sql
-- taken from -- http://vrypan.net/log/archives/2005/03/10/migrating-from-drupal-to-wordpress/ -- and then improved-- these lines will result in the deletion of all existing posts, comments -- and categories. Comments these out using '--' or /* ... */ if you don't -- want that to happen DELETE FROM weblog_wp_categories ; DELETE FROM weblog_wp_posts ; DELETE FROM weblog_wp_post2cat ; DELETE FROM weblog_wp_comments ; /* -- does not work (think it is to do with password issues) -- also causes problems with auto-increment delete from weblog_wp_users; INSERT INTO weblog_wp_users (ID, user_login, user_pass, user_nickname, user_email, user_registered) SELECT uid, name, pass, name, mail, FROM_UNIXTIME(timestamp) FROM users; */ 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_author, post_date, post_content, post_title, post_excerpt, post_name, post_modified ) SELECT nid, 1, FROM_UNIXTIME(created), body, title, teaser, concat('OLD',nid), FROM_UNIXTIME(changed) FROM node WHERE type='blog' OR type='page' OR type='story' OR type='forum' ; 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,' ', comment), thread FROM comments ; DROP TABLE term_data; DROP TABLE term_hierarchy; DROP TABLE node; DROP TABLE term_node; DROP TABLE comments; DROP TABLE users;
migrate-drupal-data.py
#!/usr/bin/env python
import os
# target wordpress db information
user = 'your_user_name'
db = 'your_db_name'
# replace this with the path to your dump from drupal
drupalDbDump = '~/tmp/drupal-db-dump.sql'
# path to drupal conversion sql script
templateConvertDrupalSql = 'convert-drupal-data.sql'
# tmp file used as an intermediary
convertDrupalData = 'tmp_sql.sql'
# default wordpress prefix used in templateConvertDrupalSql script
# you shouldn't have to change this
templatePrefix = 'weblog_'
# your wordpress prefix
wpPrefix = ''
def prepareConvertSql():
ff = file(templateConvertDrupalSql)
tstr = ff.read()
ff.close()
tstr = tstr.replace(templatePrefix, wpPrefix)
ff2 = file(convertDrupalData, 'w')
ff2.write(tstr)
ff2.close()
if __name__ == '__main__':
sqlCmd = 'mysql -u %s -p %s < %s'
cmdInsertDrupalData = sqlCmd % (user, db, drupalDbDump)
cmdConvertDrupalData = sqlCmd % (user, db, convertDrupalData)
# getData()
prepareConvertSql()
os.system(cmdInsertDrupalData)
os.system(cmdConvertDrupalData)

May 31st, 2006 at 7:48 pm
[…] Their in a SQL database sitting on my harddrive where nobody can read them. But I’m trying to fix that, and this might help me. Of course, this means that I have to fuck around with database scripts and, since I’m pretty inept witth that task, it’s going to take me a few hours and a lot of screaming. Plus I’ll probably lose all my current Wordpress posts and user accounts. […]
August 20th, 2006 at 9:14 am
for rgrp
perhaps you could help me convert one drupal site to wordpress
i am offering $50 no rush deadline
please reply by email if intrested
August 21st, 2006 at 6:10 pm
mik: I’m sorry to say I’m not able to help you with your conversion. Have you tried using the scripts above?
August 25th, 2006 at 10:57 am
Hi
perhaps you could give istructions simple ppl?
i have not tied, i have no idea how to start
such as what preparation before using scripts?
where to put the scripts in what folder?
where to put various sql files?
how do i know if and where phyton is installed on my server?
will this script work for drupal 4.4.2?
thanks a lot for time and patience
August 31st, 2006 at 4:57 pm
mik: I have reworked the post to provided proper instructions for usage. Let me know if that helps. Regarding drupal 4.4: I used this script to convert a drupal 4.5 db without problem and I don’t think there were any schema changes between 4.4 and 4.5 that would affect the tables being used here so I think it should work fine. If you do encounter errors try taking a look at your drupal db dump and comparing table columns with those used by the convert-drupal-data.sql script.
September 15th, 2006 at 3:13 am
[…] 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. […]
January 2nd, 2007 at 7:51 am
[…] http://www.thefactz.org/ideas/archives/62 […]
August 13th, 2007 at 2:49 am
[…] The changeover was fairly easy to do, thanks largely to this post: Migrating Drupal to Wordpress. Since that post is almost two years old, the sql needed some tweaking to work with the 5.x series of Drupal. If you need the tweak’s I’ve made them available here: convert-drupal-wp.txt […]