sudo cat /etc/mysql/debian.cnf
user = debian-sys-maint
password = xxxxx
import pandas as pd
from sqlalchemy import create_engine
host = '127.0.0.1'
db = 'test'
user = 'debian-sys-maint'
password = 'xxx'
print(str(r"mysql+pymysql://%s:" + '%s' + "@%s/%s") % (user, password, host, db))
engine = create_engine(str(r"mysql+pymysql://%s:" + '%s' + "@%s/%s") % (user, password, host, db))
try:
df = pd.DataFrame([[1,'x'],[2,'y']],columns=list('ab'))
df.to_sql('test1',con=engine,if_exists='replace',index=False)
except Exception as e:
print(e)