What is mdb file extension
Mdb file extension is a format use to save Microsoft Access files. They can be seen as an equivalent of sqlite in the sense where they store all informations for the access database.
How to convert .mdb to .sql
After trying multiple method, I end up using a docker image which include the mdb tools library. It’s a set of tools allowing you to work with Microsoft Access files. You can find the image repository, I used here https://github.com/Rillke/mdbtools-docker.
I use the following bash script named convert-mdb-to-mysql.sh
#!/bin/bash
FILE_IN=$1
FILE_OUT=$2
docker run -it --rm -v "$PWD":/opt/mdbdata rillke/mdbtools bash -c "to_mysql.sh /opt/mdbdata/${FILE_IN}" > ${FILE_OUT}
sed -i -e "s/\r//g" ${FILE_OUT}
sed -i '/^--/ d' ${FILE_OUT}
sed -i '/ ();$/ d' ${FILE_OUT}
sed -i '/^ERROR/ d' ${FILE_OUT}
sed -i '/^Error/ d' ${FILE_OUT}
sed -i '/^CRITICAL/ d' ${FILE_OUT}
sed -i '/ALTER TABLE .* ADD INDEX .*;/ d' ${FILE_OUT}
sed -i '/ALTER TABLE .* ADD PRIMARY KEY .*;/ d' ${FILE_OUT}
sed -i '/DROP TABLE IF EXISTS to;/ d' ${FILE_OUT}
sed -i '/DROP TABLE IF EXISTS delete;/ d' ${FILE_OUT}
sed -i '/DROP TABLE IF EXISTS Table;/ d' ${FILE_OUT}
sed -i '/DROP TABLE IF EXISTS des;/ d' ${FILE_OUT}
sed -i '/DROP TABLE IF EXISTS erreurs;/ d' ${FILE_OUT}
The command to use this script is :
convert-mdb-to-mysql.sh input.mdb output.sql