python pymysql设置自动提交false失败 [英] python pymysql set autocommit false fails
本文介绍了python pymysql设置自动提交false失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的脚本从文件中读取MYSQL UPDATE查询,然后应通过使用autocommit = 0立即执行它们.但是,如果删除conn.commit()
,它仍会逐个运行,尽管我尚未提交.错误在哪里?
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()
推荐答案
MySQL中的MyISAM存储引擎不支持事务.只有InnoDB支持ACID事务.
Transactions are not supported with MyISAM storage engine in MySQL. Only InnoDB suports ACID transactions.
就事务而言,MyISAM表始终有效地在 自动提交= 1模式.
In transactional terms, MyISAM tables effectively always operate in autocommit = 1 mode.
mysql> SELECT table_name,engine FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema=DATABASE();
+--------------+--------+
| table_name | engine |
+--------------+--------+
| stats | MyISAM |
+--------------+--------+
1 row in set (0.00 sec)
将表移动到 MySQL存储引擎支持交易.
这篇关于python pymysql设置自动提交false失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文