MySQL Forums
Forum List  »  Connector/Python

Problem with inserting data into MySQL
Posted by: Mohammad Mahdi
Date: October 29, 2022 02:18AM

Hi
I want to read the data of a sensor and transfer it to MySQL local host with "mysql.connector". The problem is that it reads the data as a list containing 500 data (that is, it reads 500 to 500, not one by one). This is my code:

master_data = master_task.read(number_of_samples_per_channel=500)
sql = "INSERT INTO vib_data2 (data) VALUES (%s)"
val = list(master_data, )
mycursor.executemany(sql, val)
mydb.commit()


I got this error:
"Could not process parameters: float(-0.15846696725827258), it must be of type list, tuple or dict"


I can fix the problem with this code:

for i in master_data:
sql = "INSERT INTO vib_data2 (data) VALUES (%s)"
val = (str(I),)
mycursor.execute(sql, val)
mydb.commit()


But the code execution time is very long (more than one second) and thus some of the data is lost.
Thank you for helping to correct the code

Options: ReplyQuote


Subject
Written By
Posted
Problem with inserting data into MySQL
October 29, 2022 02:18AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.