pandas to mysql error: `ValueError: database flavors mysql is not supported`

pandas to mysql error: `ValueError: database flavors mysql is not supported`

我需要将 DataFrame 中的数据加载到 mysql。 我尝试使用 df.to_sql ,遵循 this documentation,建议使用:.to_sql(name, con, flavor='mysql', if_exists='fail', index=True, index_label=None)

我收到这个错误:ValueError: database flavors mysql is not supported

我怎样才能绕过这个问题?

风格 'mysql' 在 pandas 0.19 版中已弃用。您必须使用 sqlalchemy 的引擎来创建与数据库的连接。

from sqlalchemy import create_engine
engine = create_engine("mysql+mysqldb://USER:PASSWORD@HOST/DATABASE")
df.to_sql(name, con=engine, if_exists='fail', index=True, index_label=None)

定义引擎时,需要指定用户、密码、主机和数据库。