How to access MDB database through Python script in Linux

Source: Internet
Author: User
If you connect to the MDB database in a Linux system and connect directly, the MDB default driver does not recognize the non-Windows path, so you cannot use a regular connection Way

Driver={microsoft Access DRIVER (*.mdb)};D Bq=c:\\dir\\file.mdb

Installation

Here we need to use some libraries to implement third-party drivers

We need to install these packages: Mdbtools, UnixODBC, LIBMDBODBC

If you cannot find LIBMDBODBC in a system that supports Deb, add the following path to the list of software sources

Deb Http://ftp.de.debian.org/debian Squeeze Main

After you update the source, you can install LIBMDBODBC.
Configuration

After installing the required packages, you need to do some configuration to support the LIBMDBODBC driver.

Copy the Code code as follows:

/etc/odbcinst.ini

[MDBTOOLSODBC]
Description = MDB Tools ODBC
Driver =/usr/lib/libmdbodbc.so.0
Setup =
FileUsage =
CPTimeout =
Cpreuse =

/etc/odbc.ini or ~/.odbc.ini

Copy the Code code as follows:

[Test]
Description = Microsoft Access Try DB
Driver = Mdbtoolsodbc
Database =/path/to/mdb/file/test.mdb
Servername = localhost
Username =
Password =
Port = 5432

Code

Once the data source is configured, it can be used in any application that supports ODBC access, with PYODBC as an example

#-*-coding:utf-8-*-import pyodbcconn = pyodbc.connect (' dsn=test '); cursor = Conn.cursor () cursor.execute (' SELECT * FROM "Save" ') for Row in Cursor.fetchall (): Print row. Name

Note: If the name of the Chinese table or field, and so on, you need to include it in double quotation marks, or it will be wrong, of course, the table name into Chinese so two, or not recommended to use

Pyodbc is a very good library, API is also very useful, but the Chinese support is not good, it does not default to Unicode processing data, so for Chinese-related applications, coding problems everywhere, had to slowly toss.

  • 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.