shayms8
shayms8

Reputation: 771

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

I need to load data that i have in a DataFrame into mysql. I tried to use the df.to_sql , following this documentation, that suggest using: .to_sql(name, con, flavor='mysql', if_exists='fail', index=True, index_label=None)

And i get this error: ValueError: database flavors mysql is not supported

How can i bypass this problem ?

Upvotes: 1

Views: 2175

Answers (1)

Marine
Marine

Reputation: 408

The flavor 'mysql' is deprecated in pandas version 0.19. You have to use the engine from sqlalchemy to create the connection with the database.

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)

When defining your engine, you need to specify your user, password, host and database.

Upvotes: 3

Related Questions