来自 MySQL docs我得到以下信息(关于错误代码):
-
1205 (ER_LOCK_WAIT_TIMEOUT)
Lock wait timeout expired. The statement that waited too long was rolled back (not the entire transaction). You can increase the value of the innodb_lock_wait_timeout configuration option if SQL statements should wait longer for other transactions to complete, or decrease it if too many long-running transactions are causing locking problems and reducing concurrency on a busy system.
在这条语句中,明确区分了语句回滚和事务回滚。我的问题是如何回滚一条语句,而其中运行的事务不回滚?更有什者,我在一个事务中得到这样的锁超时,整个事务被回滚。有人可以启发我吗?
最佳答案
与事务类似,语句也是原子的。一旦语句开始执行数据更改,就会保存原始状态(实际上会记录更改)。如果语句由于任何原因(超时、与刚提交的事务冲突)而失败,则更改必须恢复到原始状态。该语句将报告失败,但事务仍处于打开状态,您可以继续进行事务,就像语句从未执行过一样。
这其实类似于savepoint——你可以想象在每条statement savepoint被记录之前,statement完成之后,savepoint被commit。但是,这对外部事务或保存点没有影响。
关于mysql - MySQL 中的语句回滚与事务回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34924495/