Tutorial on accessing mdb Database instance using pypyodbc in Mac OS X

Source: Internet
Author: User
Tags driver manager mdb database odbc

First, use brew to install unixodbc and mdbtools. unixodbc is the odbc Driver Manager. mdbtools provides a set of mdb operation tools. More importantly, mdbtools provides mdb drivers.

$ Brew install unixodbc
$ Brew install mdbtools

However, after the installation is complete, the mdbtools driver dynamic link library libmdbodbc. dylib is not found in the/usr/local/lib directory.

You can view the mdbtools options and find that:

$ Brew options mdbtools
-- With-man-pages
Build manual pages

Mdbtools formula does not provide the -- with-unixodbc option. By default, the mdb driver is not built. Therefore, you need to manually compile and install the mdb driver provided by mdbtools.

Compile and install libmdbodbc

When installing mdbtools, brew has downloaded the mdbtools source package to the/Library/Caches/Homebrew/Directory. Therefore, you can directly compile and install this source package.

$ Tar zxvf mdbtools-0.7.1
$ Mdbtools-0.7.1 cd
$ Autoreconf-I-f
$./Configure -- with-unixodbc =/usr/local -- disable-man
$ Make
$ Cd src/odbc
$ Sudo make install

In this way, the libmdbodbc driver is installed in the/usr/local/lib directory. The source code of libmdbodbc is in the src/odbc directory.

Configure unixodbc

Because all brew packages are installed under/usr/local, the odbcinst. ini and odbc. ini files under the/usr/local/etc/directory should be configured here.
The odbcinst. ini configuration is as follows:

[MDBTools]
Description = MDBTools Driver
Driver = libmdbodbc. dylib
Setup = libmdbodbc. dylib
FileUsage = 1
UsageCount = 1

Then you can access the mdb file like on the linux platform.

$ Python3
>>> Import pypyodbc
>>> Conn = pypyodbc. connect ('driver = MDBTools; DBQ =/path/to/record. mdb ')

Because the odbc driver provided by mdbtools is used here, Chinese character encoding conversion still exists when used with pypyodbc. Please parameter: pypyodbc in linux to read Chinese garbled characters in the GB-encoded mdb solution.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.