简体   繁体   English

如何将Microsoft Access数据库转换为SQL数据库(然后用熊猫打开它)?

[英]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 . 假设我有以下Microsoft Access数据库: 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. 我要实现的主要目的是使用pandas中的read_sql()以便我可以使用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)? 有没有一种方法可以将Microsoft Access数据库转换为SQL数据库...最终传递给熊猫(全部使用python)?

Figured out a simple way to do this with pyodbc (I'm going to type an arbitrary example below)! 找出了一种使用pyodbc实现此目的的简单方法(我将在下面输入一个任意示例)!

import pandas as pd
import pyodbc

For some reason the MDB path needs double backslashes in place of each backslash. 由于某些原因,MDB路径需要双反斜杠来代替每个反斜杠。

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 下载Microsoft SQL Server迁移助手v6.0进行访问

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. 确保您的计算机是64位的,那么迁移助手工具将是64位的,因此您的访问软件也需要也是64位的。 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. 只需打开SQL Server迁移助手工具,然后选择访问.mdb数据库或所有表的存储位置(如果您将它们拆分并导入),然后选择与SQL Server的连接,然后单击末尾旁边的,即可创建数据库,所有表,并将所有数据迁移到SQL Server。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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