Migrating Drupal to WordPress
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)
10 Responses to Migrating Drupal to WordPress
-
Categories
- *nix
- Academic
- Activity Updates
- Books
- Cinema
- Code
- Command Line
- Copyright
- Culture and Society
- Data Digging
- Economics
- EUPD
- External
- Filesharing
- Governance
- Hacks
- Happiness
- Hardware
- History
- Innovation and Intellectual Property
- Intellectual Myths
- Javascript
- Knowledge Systems
- Miscellaneous
- Musings
- Notes
- Open Bibliographic Data
- Open Data
- Open Knowledge Foundation
- Openness
- Own Work
- Papers
- People
- Photos
- Platforms
- Poetry
- Policy
- PSI
- Python
- Quote
- RDF
- Shuttleworth Fellow
- Software
- Sysadmin
- Talks
- Transaction Costs
- Work In Progress
-
Articles
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- June 2004
- May 2004
- March 2004
- October 2003
-
Meta





[...] 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. [...]
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
mik: I’m sorry to say I’m not able to help you with your conversion. Have you tried using the scripts above?
Hi i have not tied, i have no idea how to start
perhaps you could give istructions simple ppl?
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
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.
[...] 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. [...]
[...] http://www.thefactz.org/ideas/archives/62 [...]
[...] 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 [...]
[...] the structure of databases has changed over a period of time. I was following the instructions at http://www.rufuspollock.org/2005/10/10/migrating-drupal-to-wordpress/ and failed to import the posts. Thus I made my own SQL script for importing the posts. Essentially [...]
[...] 10/10/2005 Migración de Drupal a WordPress [...]