Skip to content

Instantly share code, notes, and snippets.

@burningTyger
Created October 21, 2015 21:35
Show Gist options
  • Save burningTyger/31dfdb67afbc4f68ec2f to your computer and use it in GitHub Desktop.
Save burningTyger/31dfdb67afbc4f68ec2f to your computer and use it in GitHub Desktop.

Revisions

  1. burningTyger created this gist Oct 21, 2015.
    26 changes: 26 additions & 0 deletions mdb2sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/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