Skip to content

Instantly share code, notes, and snippets.

@burningTyger
Created October 21, 2015 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burningTyger/31dfdb67afbc4f68ec2f to your computer and use it in GitHub Desktop.
Save burningTyger/31dfdb67afbc4f68ec2f to your computer and use it in GitHub Desktop.
use mdbtools to convert mdb to sql
#!/bin/bash
# found this here: http://stackoverflow.com/questions/5722544/how-can-i-convert-an-mdb-access-file-to-mysql-or-plain-sql-file
#
# Create DB like this: CREATE DATABASE xyc;
# To invoke it simply call it like this:
# ./mdbconvert.sh accessfile.mdb mysqldatabasename
TABLES=$(mdb-tables -1 $1)
MUSER="root"
MPASS="yourpassword"
MDB="$2"
MYSQL=$(which mysql)
for t in $TABLES
do
$MYSQL -u $MUSER -p$MPASS $MDB -e "DROP TABLE IF EXISTS $t"
done
mdb-schema $1 mysql | $MYSQL -u $MUSER -p$MPASS $MDB
for t in $TABLES
do
mdb-export -D '%Y-%m-%d %H:%M:%S' -I mysql $1 $t | $MYSQL -u $MUSER -p$MPASS $MDB
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment