my script reads MYSQL UPDATE queries from a file and then should execute them at once by using autocommit = 0. However, if I remove conn.commit()
it still runs one by one, although I have not commited. Where is the error?
import pymysql
conn = pymysql.connect(host='x', unix_socket='/tmp/mysql.sock',user='x', passwd='x', db='x')
fileHandle = open ( 'mysqlout.txt' )
fileList = fileHandle.readlines()
fileHandle.close()
i = 1
weiter = input("Execute MYSQL file? ")
if (weiter == 'y'):
cur = conn.cursor()
cur.execute('SET autocommit = 0')
conn.commit()
for fileLine in fileList: #-----each line is an UPDATE...query
cur.execute(fileLine)
i = i + 1
print(i," ---",round(i / len(fileList),3))
#conn.commit()
conn.close()