How can I convert an MDB (Access) file to MySQL (or plain SQL file)?
You want to convert mdb to mysql (direct transfer to mysql or mysql dump)?
Try a software called Access to MySQL.
Access to MySQL is a small program that will convert Microsoft Access Databases to MySQL.
- Wizard interface.
- Transfer data directly from one server to another.
- Create a dump file.
- Select tables to transfer.
- Select fields to transfer.
- Transfer password protected databases.
- Supports both shared security and user-level security.
- Optional transfer of indexes.
- Optional transfer of records.
- Optional transfer of default values in field definitions.
- Identifies and transfers auto number field types.
- Command line interface.
- Easy install, uninstall and upgrade.
See the aforementioned link for a step-by-step tutorial with screenshots.
If you have access to a linux box with mdbtools installed, you can use this Bash shell script (save as mdbconvert.sh):
#!/bin/bashTABLES=$(mdb-tables -1 $1)MUSER="root"MPASS="yourpassword"MDB="$2"MYSQL=$(which mysql)for t in $TABLESdo $MYSQL -u $MUSER -p$MPASS $MDB -e "DROP TABLE IF EXISTS $t"donemdb-schema $1 mysql | $MYSQL -u $MUSER -p$MPASS $MDBfor t in $TABLESdo mdb-export -D '%Y-%m-%d %H:%M:%S' -I mysql $1 $t | $MYSQL -u $MUSER -p$MPASS $MDBdone
To invoke it simply call it like this:
./mdbconvert.sh accessfile.mdb mysqldatabasename
It will import all tables and all data.
I modified the script by Nicolay77 to output the database to stdout (the usual way of unix scripts) so that I could output the data to text file or pipe it to any program I want. The resulting script is a bit simpler and works well.
Some examples:
./mdb_to_mysql.sh database.mdb > data.sql./mdb_to_mysql.sh database.mdb | mysql destination-db -u user -p
Here is the modified script (save to mdb_to_mysql.sh)
#!/bin/bashTABLES=$(mdb-tables -1 $1)for t in $TABLESdo echo "DROP TABLE IF EXISTS $t;"donemdb-schema $1 mysqlfor t in $TABLESdo mdb-export -D '%Y-%m-%d %H:%M:%S' -I mysql $1 $tdone