使用innondb引擎在mysql数据库中插入python脚本时出现问题

2024-09-29 23:17:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正面临一个问题,我正试图使用InnonDB引擎将python脚本中的数据添加到mysql数据库中,它在mysql数据库的myisam引擎中运行良好。但myisam引擎的问题是它不支持外键,所以我必须在数据库中插入/删除记录的每个位置添加额外的代码

有人知道为什么InnonDB不使用python脚本和可能的解决方案吗


Tags: 数据代码引擎脚本数据库记录mysql解决方案
2条回答

Python DB API默认情况下禁用自动提交

从谷歌粘贴(第一页,第二个结果)

MySQL :: MySQL 5.0 Reference Manual :: 13.2.8 The InnoDB ... By default, MySQL starts the session for each new connection with autocommit ...dev.mysql.com/.../innodb-transaction-model.html

但是

显然Python是以非自动提交模式启动MySQL的,请参见:
http://www.kitebird.com/articles/pydbapi.html

从文章中:

The connection object commit() method commits any outstanding changes in the current transaction to make them permanent in the database. In DB-API, connections begin with autocommit mode disabled, so you must call commit() before disconnecting or changes may be lost.

可怜虫,不知道如何克服这一点,我不想通过猜测把你引入歧途。 我建议提出一个新问题,题为:

如何在MySQL python DB-API中启用自动提交模式

祝你好运

InnoDB是事务性的。插入/删除/更新后需要调用connection.commit()

编辑:您可以调用connection.autocommit(True)来启用自动提交

相关问题 更多 >

    热门问题