Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Forked from turicas/mdb2sql.sh
Last active December 21, 2015 11:59
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 gabrielflorit/6302543 to your computer and use it in GitHub Desktop.
Save gabrielflorit/6302543 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Convert a MDB file (Access) to SQL
# Needs mdbtools[http://mdbtools.sourceforge.net/]
# run 'aptitude install mdbtools' on Debian/Ubuntu
# Created by Álvaro Justen <https://github.com/turicas>
# Modified by Gabriel Florit to run on Mac OS X
# License: GPLv2
mdb=$1
sql=$2
if [ -z "$2" ]; then
echo 'This script convert a MDB file to SQL file. You need to specify the name of both'
echo "Usage: $0 <mdb_file> <sql_file>"
exit 1
fi
if [ -z "$(which mdb-tables)" ]; then
echo 'You need mdbtools installed.'
echo 'Learn more at http://mdbtools.sourceforge.net/'
echo 'If you use Debian/Ubuntu, just execute:'
echo ' sudo aptitude install mdbtools'
exit 2
fi
mdb-schema $mdb > $sql
sed -i.bak 's/Long Integer/INT(11)/g; s/Text /VARCHAR/g' $sql
for table in $(mdb-tables $mdb); do
mdb-export -I mysql -R ';' $mdb $table >> $sql
done
sed -i.bak '/^-\{2,\}/d; s/DROP TABLE /DROP TABLE IF EXISTS /' $sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment