Have you tried to connect MySQL DB in python ?
So this is the recipe on how we can connect MySQL DB in Python.
import sqlalchemy as sa
import pandas as pd
Here we have improted pandas and sqlalchemy which will be needed.
We have first used iris dataset for this and passed the information of SQL and applied dataset.to_sql to save the file as SQL.
dataset = pd.read_csv("iris.data.csv")
engine_str = (
"mysql+pymysql://{user}:{password}@{server}/{database}".format(
user = "root",
password = "root888",
server = "localhost",
database = "datasciencerecipes"))
engine = sa.create_engine(engine_str)
conn = engine.connect()
# check whether connection is Successful or not
if (conn):
print("MySQL Connection is Successful ... ... ...")
else:
print("MySQL Connection is not Successful ... ... ...")
dataset.to_sql(name="irisdata", con=engine,
schema="datasciencerecipes",
if_exists = "replace", chunksize = 1000,
index=False)
conn.close()