文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

17.20.5 InnoDB 错误处理17.20.5 InnoDB Error Handling

以下内容描述了 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 MySQL Table is full error occurs and InnoDB rolls back the SQL statement.

  • 事务 死锁 会导致 InnoDB 回滚 整个 事务。发生这种情况时,请重试整个事务。A transaction deadlock causes InnoDB to 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 causes InnoDB to 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-timeout enabled. Retry the statement if using the default behavior, or the entire transaction if --innodb-rollback-on-timeout is 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 the IGNORE option in your statement.

  • row too long error 会回滚该 SQL 语句。A row too long error rolls back the SQL statement.

  • 其他错误大多由 MySQL 代码层(高于 InnoDB 存储引擎层)检测到,并会回滚相应的 SQL 语句。在单个 SQL 语句回滚中,锁不会被释放。Other errors are mostly detected by the MySQL layer of code (above the InnoDB storage 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.