gpt4 book ai didi

mysql - 没有 "commit"的单个 "begin transaction"语句

转载 作者:行者123 更新时间:2023-11-29 01:10:20 26 4
gpt4 key购买 nike

我正在使用带有 mysqldb 适配器的 web2py dal 连接到 mysql 服务器。

我的问题:

  1. 为什么在“set autocommit=0”之后需要一个“commit”而不是“begin transaction
  2. 如果 autocommit=0,“select”语句是否开始事务?

服务器信息:Innodb引擎自动提交=1(默认值)tx_isolation=repeatable-read(默认值)

一般日志:

100356 10:00:00 123456 Connect  dummy@172.0.0.1 on dummydb
123456 Query SET NAMES 'utf8'
123456 Query SET AUTOCOMMIT = 0
123456 Query COMMIT
123456 Query SET FOREIGN_KEY_CHECKS=1
123456 Query SET sql_mode='NO_BACKSLASH_ESCAPES'

最佳答案

呃...因为你禁用了自动提交????

这里有一个很好的解释:

http://rpbouman.blogspot.com/2007/02/mysql-transactions-and-autocommit.html

With autocommit enabled, every statement is wrapped within its own transaction. Successful execution of a statement is implicitly followed by a COMMIT, and the occurrence of an error aborts the transaction, rolling back any changes.

By default, autocommit is enabled in MySQL.

换句话说:

  1. “交易”不一定只是“将多个语句作为一个原子实体执行”

  2. 自动提交给您一个语句 == 1 个事务的“错觉”

  3. 事实上,“automcommit off”为您提供了“一个语句 == 0 个事务”

来自同一个链接:

... The whole point of having autocommit off is that you can issue multiple statements and commit them all at once.

关于mysql - 没有 "commit"的单个 "begin transaction"语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8799703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com