[英]Extract from DataBase using Python
I wrote a small script in Python that could help me to extract data from a database. 我用Python编写了一个小脚本,可以帮助我从数据库中提取数据。 Here is my script :
这是我的脚本:
#!/usr/bin/python3
import pandas as pd
from sqlalchemy import create_engine
#connect to server
mytab = create_engine('mssql+pyodbc://test:test1@mypass')
#sql query that retrieves my table
df = pd.read_sql('select * from FO_INV', mytab)
#query result to excel file
df.to_csv('inventory.csv', index=False, sep=',', encoding='utf-8')
Everything works fine if I choose to select top 100 rows for example. 例如,如果我选择选择前100行,则一切正常。 But for the whole table, it take forever !!!
但是对于整个桌子,它需要永远的时间! Do you have any idea or recommendations, please ?
请问您有什么想法或建议吗? Thank you in advance :)
先感谢您 :)
I would suggest using pyodbc
instead of SQLALCHEMY
. 我建议使用
pyodbc
而不是SQLALCHEMY
。
Something like this: 像这样:
import pyodbc
mytab = pyodbc.connect('DRIVER={SQL SERVER};SERVER=.\;DATABASE=myDB;UID=user;PWD=pwd')
Check your timings with this. 以此检查您的时间安排。 This should be faster.
这应该更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.