python 使用mdbtools将.mdb转换为.sqlite和.csv

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用mdbtools将.mdb转换为.sqlite和.csv相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env sh
# prerequisite https://github.com/brianb/mdbtools
#
# if your mdb is encoded in certain character set
# do something like this
# export MDB_ICONV="Big-5"
# export MDB_JET3_CHARSET="Big-5"
#
# under zsh
# for f (**/*.mdb) {~/dump.sh $f}
#

python ~/AccessDump.py $1 | sqlite3 $1.sqlite

for x in `mdb-tables -1 $1`; do mdb-export $1 $x >> $1.$x.csv ; done
#!/usr/bin/env python
#
# AccessDump.py
# A simple script to dump the contents of a Microsoft Access Database.
# It depends upon the mdbtools suite:
#   http://sourceforge.net/projects/mdbtools/

import sys, subprocess, os

DATABASE = sys.argv[1]

# Dump the schema for the DB
subprocess.call(["mdb-schema", DATABASE, "mysql"])

# Get the list of table names with "mdb-tables"
table_names = subprocess.Popen(["mdb-tables", "-1", DATABASE],
                               stdout=subprocess.PIPE).communicate()[0]
tables = table_names.splitlines()

print "BEGIN;" # start a transaction, speeds things up when importing
sys.stdout.flush()

# Dump each table as a CSV file using "mdb-export",
# converting " " in table names to "_" for the CSV filenames.
for table in tables:
    if table != '':
        subprocess.call(["mdb-export", "-I", "mysql", DATABASE, table])

print "COMMIT;" # end the transaction
sys.stdout.flush()

以上是关于python 使用mdbtools将.mdb转换为.sqlite和.csv的主要内容,如果未能解决你的问题,请参考以下文章

在 Python 中将 .mdb 文件转换为 .csv 时包括列名

我可以使用 .NET 将 ACCDB 文件转换为 MDB

将悖论转换为 MDB

mdb 工具 sql 查询表名空间分隔

使用 PowerShell 将多个 .accdb 文件转换为 .mdb?

将 Mdb 转换为 Sql Server