I have an requirement wherein I would like to import all the tables stored in the sql database into python. I have successfully created a python code for it as follows:
import pandas as pd
import mysql.connector
from pandas import DataFrame
db = mysql.connector.connect(host="localhost", user="root", passwd="********")
pointer = db.cursor()
pointer.execute("use stock")
pointer.execute("SELECT * FROM 3iinfotech")
data = pointer.fetchall()
data = DataFrame(data,columns =['date','open','high','low','close','volume'])
Using this I am able to successfully import the Tables data into a pandas Dataframe.
But as can be seen from the database schema there are multiple tables which will again increase in the future.
Full database schema along with output of the table
The dataframe looks like:
Imported table from sql converted to DataFrame
Is there any ways using loops or by any other methods that this script can be automated for all the tables in a given database.
I referred the following :
Importing multiple SQL tables using pandas
But this does not work in my case.
Thanks.....