首页 > 解决方案 > 向mysql插入大量行

问题描述

我想从 MSSQL 表中读取然后插入到 MySQL 表中,但我无法将我的 MSSQL 结果格式化为executemany它们

    cursor.execute('select * from table') # MSSQL
    rows = cursor.fetchall()
    many_rows = []
    for row in rows:
        many_rows.append((row))
    sql = "insert into mysql.table  VALUES (NULL, %s) on duplicate key update REFCOLUMN=REFCOLUMN" # MYSQL
    mycursor.executemany(sql, many_rows)
    mydb.commit()

这给出了Failed executing the operation; Could not process parameters First NULL 用于 id 列和 %s 用于其他 49 列。它以 1 x 1 的方式工作,但在远程连接上需要很长时间

编辑

我的示例打印输出many_rows

[
(49 columns' values, all string and separated by comma),
(49 columns' values, all string and separated by comma),
(49 columns' values, all string and separated by comma),
...
]

标签: pythonmysql

解决方案


我能够通过附加如下数据来解决我的问题:

many_rows.append((list(row)))


推荐阅读