Skip to content

Instantly share code, notes, and snippets.

@martjanz
Last active October 28, 2015 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martjanz/36448c791fdd43464b30 to your computer and use it in GitHub Desktop.
Save martjanz/36448c791fdd43464b30 to your computer and use it in GitHub Desktop.
Access mdb to SQLite converter (using mdbtools).
#!/usr/bin/env python
#
# AccessDump.py
# A simple script to dump the contents of a Microsoft Access Database.
# It depends upon the mdbtools suite:
# http://sourceforge.net/projects/mdbtools/
import sys, subprocess, os
DATABASE = sys.argv[1]
# Dump the schema for the DB
subprocess.call(["mdb-schema", DATABASE, "mysql"])
# Get the list of table names with "mdb-tables"
table_names = subprocess.Popen(["mdb-tables", "-1", DATABASE],
stdout=subprocess.PIPE).communicate()[0]
tables = table_names.splitlines()
print "BEGIN;" # start a transaction, speeds things up when importing
sys.stdout.flush()
# Dump each table as a CSV file using "mdb-export",
# converting " " in table names to "_" for the CSV filenames.
for table in tables:
if table != '':
subprocess.call(["mdb-export", "-I", "mysql", DATABASE, table])
print "COMMIT;" # end the transaction
sys.stdout.flush()
MDB_JET3_CHARSET="cp1252"
python mdb2sql.py access.mdb | sqlite3 db.sqlite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment