1

I am extracting data from google sheet and I have to insert that data frame to MySQL localhost database.

I have tried this, and it doesn't work for me: How to insert pandas dataframe via mysqldb into database?

df.to_sql(con=mydb,schema = 'automate', name='live_nos', if_exists='append', flavor='mysql') 

I am getting an error. TypeError: to_sql() got an unexpected keyword argument 'flavor'

When I remove the flavor from this it gives my programming error as follow.

DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': Not all parameters were used in the SQL statement.

I am using mysql.connector.connect to make the connection :-

mydb = mysql.connector.connect(
  host="127.0.0.1",
  user="root",
  passwd="12345678"
)

This is my data frame which I extract from the google sheet.

Columns :- dates A B C D E

Row to insert :- 5/1/2019 2712 4854 1273 711 345

I want to insert this pandas data frame into MySQL localhost:-

sql = "select * from automate.live_nos"
data = pd.read_sql_query(sql,mydb)

The table in MySQL:-

columns :- dates A B C D E

Pls help

Arvind Pant
  • 65
  • 1
  • 1
  • 8
  • Why doesn't `to_sql` work for you? – danielR9 May 01 '19 at 02:35
  • It also raises the question, that if you are reading in your data from a mysql db, and then writing to a table, why do you want to use pandas at all? – danielR9 May 01 '19 at 02:37
  • I am extracting data frame from a google sheet and I want to insert that data frame to my local database for keeping backup. I am using mysql.connector.connect to make a connection :- mydb = mysql.connector.connect( host="127.0.0.1", user="root", passwd="*******" ) When I use this: df.to_sql(con=mydb,schema = 'automate', name='live_nos', if_exists='append', flavor='mysql') I am getting an error. TypeError: to_sql() got an unexpected keyword argument 'flavor' – Arvind Pant May 01 '19 at 02:44
  • When I remove the flavor from this it gives my programming error as follow. DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': Not all parameters were used in the SQL statement. I am doing something wrong but not able to find it. – Arvind Pant May 01 '19 at 02:45
  • Ok, you really need to edit your question to provide this additional information. Please include code, and full error messages, and what you are expecting to happen https://stackoverflow.com/help/how-to-ask – danielR9 May 01 '19 at 03:06

0 Answers0