如果您使用的是ubuntu Linux,那么python mysql包中添加了一个补丁,可以设置相同的mysql选项(请参见here)。不过,我还没有试过。
不幸的是,后来由于与autoconnect和transactions(描述为here)冲突而删除了修补程序。
那一页的评论说:
1.2.2-7《无畏号》2008-06-19出版
python mysqldb(1.2.2-7)不稳定;紧急度=低
[桑德罗·托西]
*借方/控制
-“说明”中的“列出项目”行以两个空格开头,以避免重新格式化
在网页上(关闭:#480341)
[贝恩德泽米茨]
*debian/patches/02_reconnect.dpatch:
-正在删除修补程序:
风暴中的评论解释了问题:# Here is another sad story about bad transactional behavior. MySQL
# offers a feature to automatically reconnect dropped connections.
# What sounds like a dream, is actually a nightmare for anyone who
# is dealing with transactions. When a reconnection happens, the
# currently running transaction is transparently rolled back, and
# everything that was being done is lost, without notice. Not only
# that, but the connection may be put back in AUTOCOMMIT mode, even
# when that's not the default MySQLdb behavior. The MySQL developers
# quickly understood that this is a terrible idea, and removed the
# behavior in MySQL 5.0.3. Unfortunately, Debian and Ubuntu still
# have a patch right now which *reenables* that behavior by default
# even past version 5.0.3.