系统环境:win + python3.3 + mysql.connector

使用import mysql.connector导入mysql数据库的python接口库,mysql.connetor手册里有如下内容:

1.Since by default, Connector/Python does not auto commit, it is possible to
cancel transactions when using transactional storage engines such as InnoDB.

使用innodb引擎时,autocommit是默认关闭的,如果在做更新,插入,删除类操作时如果异常中断,又没有在exception里加入commit()或者rollback()进行处理,那么写锁是没有消除的,接着再重新运行程序就会因为有锁而被阻塞。

2.Since by default Connector/Python turns autocommit off, and MySQL 5.5 and later uses transactional InnoDB tables by default, it is necessary to commit your changes using the connection's commit()
method. You could also roll backusing the rollback()method。

设置autocommit的方法:cnx.autocommit = True



BTW:Oracle数据库也同理,如果autocommit是关闭的,涉及到更新数据库的操作如果异常中断而没有捕获异常进行commit或者rollback处理,再次运行此程序更新数据库将会被阻塞。