How can I convert an MDB (Access) file to MySQL (or plain SQL file)?

后端 未结 4 648
后悔当初
后悔当初 2020-12-07 07:47

Is it possible to create a Dump of SQL commands from a Microsoft Access database? I hope to convert this MDB file into a MySQL database for importing so I don\'t have to go

4条回答
  •  抹茶落季
    2020-12-07 08:21

    If you have access to a linux box with mdbtools installed, you can use this Bash shell script (save as mdbconvert.sh):

    #!/bin/bash
    
    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
    

    To invoke it simply call it like this:

    ./mdbconvert.sh accessfile.mdb mysqldatabasename
    

    It will import all tables and all data.

提交回复
热议问题