gpt4 book ai didi

mysql - 如何回滚 MySQL 中的错误事务?

转载 作者:可可西里 更新时间:2023-11-01 07:34:51 25 4
gpt4 key购买 nike

update my_table set limit_id = 2 where id='176846';

start transaction;
update my_table set limit_id = 1 where id='176846';
update my_table set limit_id = 4 where id='176846'; -- <- this one fails
commit;

select limit_id from my_table where id='176846';

我想自动回滚 - 我希望脚本输出 2,而不是 1。我无权访问正在使用的连接策略。

最佳答案

阅读这里:

http://dev.mysql.com/doc/refman/5.5/en/commit.html

By default, MySQL runs with autocommit mode enabled. This means that as soon as you execute a statement that updates (modifies) a table, MySQL stores the update on disk to make it permanent. The change cannot be rolled back.

尝试类似的东西

SET autocommit = 0;
start transaction;
(...)
commit;

关于mysql - 如何回滚 MySQL 中的错误事务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29844642/

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