简体   繁体   中英

How to convert a Microsoft Access Database to a SQL database (and then open it with pandas)?

Let's say I have the following Microsoft Access Database: random.mdb .

The main thing I'm trying to achieve is to use read_sql() from pandas so that I can work with the data I have using python. How would I approach this? Is there a way to convert the Microsoft Access database to a SQL database... to eventually pass in to pandas (all in python)?

Figured out a simple way to do this with pyodbc (I'm going to type an arbitrary example below)!

import pandas as pd
import pyodbc

For some reason the MDB path needs double backslashes in place of each backslash.

MDB = 'C:\\Some\\random\\path\\here.mdb'
DRV = '{Microsoft Access Driver (*.mdb, *.accdb)}'
con = pyodbc.connect('DRIVER={};DBQ={}'.format(DRV, MDB))

query = """select * from [Some Table Name] where Sector = 'Some Sector'"""
dataframe = pd.read_sql(query, con)

使用sql server import导出模块进行转换,但是您将需要在sql server中准备好表结构,否则可能会有许多其他实用程序

Download the Microsoft SQL Server Migration Assistant v6.0 for Access

Make sure if your computer is 64 bit then the migration assistant tool will be 64 bit so your access software needs to be 64 bit too. Just open the SQL Server Migration Assistant tool and select the access .mdb database or where all the tables are store if you have them split and import them then select the connection to the SQL Server and just click next to the end and that will create the database, all tables, and migrate all the data to your SQL Server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM