如何加快数据库中数据的更新速度?我是否需要更改循环或以不同的方式构建更新?
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 来实现此目的?或者还有其他选择吗?
最佳答案
不要在每次更新后提交。而是在每批 100 个左右之后提交。大部分实际更新工作发生在提交时。
不要忘记提交最后一批。
关于python - 如何加快MySQL更新速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74212219/