连接数据库并向数据库中写数据
‘’’
from sqlalchemy import create_engine
import pandas as pd
df = pd.DataFrame({‘catid’:self.catid,‘typeid’:self.typeid})
engine = create_engine(“mysql+pymysql://{}:{}@{}/{}?charset={}”.format(‘username’, ‘password’, ‘IP:port’, ‘数据库名字’,‘gbk’))
con = engine.connect()
df.to_sql(name=‘表名’, con=con, if_exists=‘append’, index=False)
‘’’