python3.6.2下利用pymysql库将dataframe文件写入到mysql数据库

 

#python3.6.2

import pandas as pd
import pymysql
from sqlalchemy import create_engine


# 这里一定要写成mysql+pymysql,不要写成mysql+mysqldb
engine = create_engine("mysql+pymysql://user:password@host:port/databasename?charset=utf8")

df = pd.read_excel('a.xls')

df.to_sql(name = 'table_name',con = engine,if_exists = 'append',index = False,index_label = False)

你可能感兴趣的:(python3.6.2下利用pymysql库将dataframe文件写入到mysql数据库)