如何加快MySQL的更新速度

dfty9e19  于 2022-10-31  发布在  Mysql
关注(0)|答案(1)|浏览(251)

如何加快数据库中数据的更新速度?是否需要更改循环或以其他方式生成更新?

try:
    g = 1
    for i in gate_io().values.tolist():
        with connection.cursor() as cursor:
            if i[1] != 0 and i[1] != '':
                insert_quarry = "UPDATE gate SET symbol = %s, bidPX = %s, askPx = %s WHERE id = %s"
                currency = [i[0], i[1], i[2]]
                cursor.execute(insert_quarry, (currency[0], currency[1], currency[2], g))
                connection.commit()
                g = g + 1
            else:
                continue
finally:
    connection.close()

有没有可能使用NumPy来完成这个任务?或者有没有其他的选择?

8yoxcaq7

8yoxcaq71#

不要在每次UPDATE后提交,而是在每次100次左右的批处理后提交,大多数实际的更新工作都发生在提交时。
不要忘记提交最后一批。

相关问题