import pymysql
import pandas as pd
from sqlalchemy import create_engine
# 数据库信息
mysql_setting = {
'host': 'xxxx',
'port': 3306,
'user': 'xxxx',
'passwd': 'xxxx',
# 数据库名称
'db': 'ai',
'charset': 'utf8'
}
# 表名
# 如果不存在表,则自动创建
import datetime
today = (datetime.date.today()).strftime('%Y%m%d')
table_name = 'ssales_prediction33_' + str(today)
# 文件路径
path = r'./_submission.csv'
data = pd.read_csv(path,encoding='utf-8')
print(data)
engine = create_engine("mysql+pymysql://{user}:{passwd}@{host}:{port}/{db}".format(**mysql_setting), max_overflow=5)
data.to_sql(table_name,engine,index=False,if_exists='replace',)
print('导入成功...')