Pandas Write table to MySQL: “unable to rollback”

前端 未结 4 1253
遥遥无期
遥遥无期 2021-01-12 13:53

I need help to get this working. I have a pd.DataFrame (df), which I need to load to a MySQL database. I don\'t understand what the error message means and how

4条回答
  •  别那么骄傲
    2021-01-12 14:35

    You can write pandas dataframe in mysql table using mysql flavour(with DBAPI connection) in following ways

    step1: install mysqldb module - $ sudo apt-get install python-dev libmysqlclient-dev then $ pip install MySQL-python

    step2: make a connection with mysql import MySQLdb con = MySQLdb.connect("hostname","username","password","databasename")

    step3: write pandas dataframe in mysql table by using df.to_sql df.to_sql('TableName',con = con,flavor='mysql',if_exists='replace', chunksize=100)

提交回复
热议问题