I have MySQL sever that we can call MySever there are a hundred databases on that server, we can call the databases: database1, database2, database3… database100. Each database has a table called tablepull. What I am trying to do is get each table within each database called ‘tablepull’ and store the table into a python list, the table “tablepull” has the exact same headers for each database and can save as a dataframe in pandas.
Here are the variables being defined:
from sqlalchemy import create_engine import pandas as pd UserName = MyUserName Password = MyPassword Server = MyServer Databases = [‘database1’, ‘database2’, ‘database3’,… ‘database100’] Table = tablepull I can easily pull one database table in using this syntax:
engine = create_engine(mssql:// UserName: Password@Server/Table?driver=SQL Server Native Client 11.0') connection = engine.connect() cnxn = connection.connection #Read in data into from sql table# raw_data = pd.read_sql(sql = """SELECT * FROM Table""", con = cnxn) The goal is to be able to iterate through all of the databases and grab the desired table (tablepull) for each database and save into a list. Any help or guidance would be greatly appreciated.
Thank You
pyodbc,pymssql, other? Usually ,it is denoted by themssqlkeyword in engine connection which you do not have in above redacted code.