Pandas 0.20.2 to_sql() using MySQL

前端 未结 1 717
离开以前
离开以前 2021-01-24 18:21

I\'m trying to write a dataframe to a MySQL table but am getting a (111 Connection refused) error.

I followed the accepted answer here: Writing to MySQL dat

相关标签:
1条回答
  • 2021-01-24 18:46

    Thanks to a tip from @AndyHayden, this answer was the trick. Basically replacing mysqlconnector with mysqldb was the linchpin.

    engine = create_engine('mysql+mysqldb://[user]:[pass]@[host]:[port]/[schema]', echo = False)
    df.to_sql(name = 'my_table', con = engine, if_exists = 'append', index = False)
    

    Where [schema] is the database name, and in my particular case, :[port] is omitted with [host] being localhost.

    0 讨论(0)
提交回复
热议问题