How to convert MDB (Access Database) to Mysql/MariaDB using MDB tools (linux tricks)

PC Pixel Art
Standard

Depois de instalar o mdbtools no Linux é necessário criar um shellscript, vamos lá:

 

#!/bin/bash

TABLES=$(mdb-tables -1 $1)

MUSER="rootdoMysql"
MPASS="senhadeRootdoMysql"
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

Para rodar o script…:

./mdbconvert.sh meuBancoACCESS.mdb NomeDaBaseDoMysql

Vai restaurar tudo!

OBS só funciona se CRIAR o BANCO DE DADOS ANTES, então:

 

mysql -u root -p

Coloca a senha do mysql

CREATE DATABASE NomeDaBaseDoMysql;

 

Resolvido 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.