Raspberry PiにてMDB(Access)のファイルを取り扱う

ファイル拡張子「mdb」は Microsoftの古いAccessが取り扱うデータベースのファイルです。

手元に古いAccessが無く、ubuntuやraspberry piにてファイルを取り扱う方法です。

Webを検索すると Windows対応のアプリケーションや、JAVAを利用したアプリなどがありましが、残念ながら手元の環境ではどちらも動作しませんでした。


USER@raspberrypi:~ $ sudo apt install mdbtools
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libgnutls-dane0 liblockfile-bin liblockfile1 libunbound8
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libmdb2 libmdbsql2
Suggested packages:
The following NEW packages will be installed:
  libmdb2 libmdbsql2 mdbtools
0 upgraded, 3 newly installed, 0 to remove and 139 not upgraded.
Need to get 147 kB of archives.
After this operation, 376 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ftp.udx.icscoe.jp/Linux/raspbian/raspbian buster/main armhf libmdb2 armhf 0.7.1-6 [55.2 kB]
Get:2 http://ftp.udx.icscoe.jp/Linux/raspbian/raspbian buster/main armhf libmdbsql2 armhf 0.7.1-6 [37.9 kB]
Get:3 http://ftp.udx.icscoe.jp/Linux/raspbian/raspbian buster/main armhf mdbtools armhf 0.7.1-6 [54.1 kB]
Fetched 147 kB in 3s (43.0 kB/s)
Selecting previously unselected package libmdb2:armhf.
(Reading database ... 140158 files and directories currently installed.)
Preparing to unpack .../libmdb2_0.7.1-6_armhf.deb ...
Unpacking libmdb2:armhf (0.7.1-6) ...
Selecting previously unselected package libmdbsql2:armhf.
Preparing to unpack .../libmdbsql2_0.7.1-6_armhf.deb ...
Unpacking libmdbsql2:armhf (0.7.1-6) ...
Selecting previously unselected package mdbtools.
Preparing to unpack .../mdbtools_0.7.1-6_armhf.deb ...
Unpacking mdbtools (0.7.1-6) ...
Setting up libmdb2:armhf (0.7.1-6) ...
Setting up libmdbsql2:armhf (0.7.1-6) ...
Setting up mdbtools (0.7.1-6) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10+rpi1) ...
USER@raspberrypi:~ $ 


# バージョンの表示
$ mdb-ver ./test.mdb

# テーブルの一覧
$ mdb-tables -1 ./test.mdb

# テーブルの構造
$ mdb-schema ./test.mdb
-- ----------------------------------------------------------
-- MDB Tools - A library for reading MS Access database files
-- Copyright (C) 2000-2011 Brian Bruns and others.
-- Files in libmdb are licensed under LGPL and the utilities under
-- the GPL, see COPYING.LIB and COPYING files respectively.
-- Check out http://mdbtools.sourceforge.net
-- ----------------------------------------------------------

-- That file uses encoding UTF-8

	[RcvDate]			DateTime NOT NULL,
	[Event]			Long Integer NOT NULL,
	[Freq]			Text (30) NOT NULL,
	[SIG]			Long Integer NOT NULL,
	[Remarks]			Text (510),
	[Seq]			Long Integer NOT NULL,
	[Comment]			Memo/Hyperlink (255)

	[Day]			DateTime,
	[Count]			Long Integer

	[NG_FREQ]			Text (100),
	[Remarks]			Text (100)


mdb-export -D 日付書式 ファイル名 テーブル名 > 出力先ファイル名

$ mdb-export -D "%Y-%m-%d %H:%M:%S"  ./ar5000.mdb T_Master > T_Master.CSV


mdb-export -I sqlite ファイル名 テーブル名 > 出力先ファイル名

$ mdb-export -I sqlite ./ar5000.mdb T_Master > T_Master.SQL

参考)mdb-export –help

$ mdb-export --help
mdb-export: invalid option -- '-'
mdb-export: invalid option -- 'h'
mdb-export: invalid option -- 'e'
mdb-export: invalid option -- 'l'
mdb-export: invalid option -- 'p'
Usage: mdb-export [options] <file> <table>
where options are:
  -H                   suppress header row
  -Q                   don't wrap text-like fields in quotes
  -d <delimiter>       specify a column delimiter
  -R <delimiter>       specify a row delimiter
  -I <backend>         INSERT statements (instead of CSV)
  -D <format>          set the date format (see strftime(3) for details)
  -q <char>            Use <char> to wrap text-like fields. Default is ".
  -X <char>            Use <char> to escape quoted characters within a field. Default is doubling.
  -N <namespace>       Prefix identifiers with namespace
  -b strip|raw|octal   Binary export mode.

mdb-export – Man Page


マイクロソフト Access の データ (*.mdb) を、Linux で取り扱う方法です。mdbtools を使います。Arch Linux へのインストール方法yaourt -S mdb…