Why is executemany slow in Python MySQLdb?

前端 未结 4 1307
星月不相逢
星月不相逢 2020-12-14 11:08

I am developing a program in Python that accesses a MySQL database using MySQLdb. In certain situations, I have to run an INSERT or REPLACE command on many rows. I am curren

4条回答
  •  粉色の甜心
    2020-12-14 11:30

    Strongly do not recommend to use executeMany in pyodbc as well as ceodbc both slow and contains a lot of bugs.

    Instead consider use execute and manually construct SQL query using simple string format.

    transaction = "TRANSACTION BEGIN {0} COMMIT TRANSACTION
    
    bulkRequest = ""
    for i in range(0, 100)
        bulkRequest = bulkRequest + "INSERT INTO ...... {0} {1} {2}"
    
    ceodbc.execute(transaction.format(bulkRequest))
    

    Current implementation is very simple fast and reliable.

提交回复
热议问题