以下内容描述了 InnoDB 执行错误处理的方式。InnoDB 有时只回滚失败的语句,有时会回滚整个事务。The following items describe how InnoDB
performs error handling. InnoDB sometimes rolls
back only the statement that failed, other times it rolls back the
entire transaction.
如果在表空间中用完了文件空间,会出现 MySQL
Table is full错误,并且InnoDB会回滚该 SQL 语句。If you run out of file space in a tablespace, a MySQLTable is fullerror occurs andInnoDBrolls back the SQL statement.事务 死锁 会导致
InnoDB回滚 整个 事务。发生这种情况时,请重试整个事务。A transaction deadlock causesInnoDBto roll back the entire transaction. Retry the entire transaction when this happens.锁等待超时会导致
InnoDB回滚当前语句(即等待锁并遇到超时的语句)。若要回滚整个事务,请在启动服务器时启用--innodb-rollback-on-timeout。如果使用默认行为,请重试该语句;如果启用了--innodb-rollback-on-timeout,则重试整个事务。A lock wait timeout causesInnoDBto roll back the current statement (the statement that was waiting for the lock and encountered the timeout). To have the entire transaction roll back, start the server with--innodb-rollback-on-timeoutenabled. Retry the statement if using the default behavior, or the entire transaction if--innodb-rollback-on-timeoutis enabled.在繁忙的服务器上,死锁和锁等待超时都是正常现象,应用程序需要意识到它们可能发生,并通过重试来处理它们。你可以通过在事务中对数据进行第一次更改到提交之间尽量减少操作来降低发生的可能性,这样锁保持的时间最短,锁定的行数最少。有时将工作拆分到不同的事务中可能是可行且有帮助的。Both deadlocks and lock wait timeouts are normal on busy servers and it is necessary for applications to be aware that they may happen and handle them by retrying. You can make them less likely by doing as little work as possible between the first change to data during a transaction and the commit, so the locks are held for the shortest possible time and for the smallest possible number of rows. Sometimes splitting work between different transactions may be practical and helpful.
如果在语句中未指定
IGNORE选项,重复键错误会回滚该 SQL 语句。A duplicate-key error rolls back the SQL statement, if you have not specified theIGNOREoption in your statement.row too long error会回滚该 SQL 语句。Arow too long errorrolls back the SQL statement.其他错误大多由 MySQL 代码层(高于
InnoDB存储引擎层)检测到,并会回滚相应的 SQL 语句。在单个 SQL 语句回滚中,锁不会被释放。Other errors are mostly detected by the MySQL layer of code (above theInnoDBstorage engine level), and they roll back the corresponding SQL statement. Locks are not released in a rollback of a single SQL statement.
在隐式回滚期间,以及在执行显式 ROLLBACK SQL 语句期间,SHOW PROCESSLIST 在相关连接的 State 列中显示 Rolling back。During implicit rollbacks, as well as during the execution of an
explicit
ROLLBACK SQL
statement, SHOW PROCESSLIST
displays Rolling back in the
State column for the relevant connection.