本节列出的语句(以及它们的任何同义语)会隐式结束当前会话中活动的任何事务,就好像在执行该语句前执行了COMMIT一样。The statements listed in this section (and any synonyms for them)
implicitly end any transaction active in the current session, as
if you had done a COMMIT before
executing the statement.
大多数这些语句在执行后也会导致隐式提交。其意图是将每个此类语句作为一个独立的事务进行处理。事务控制和锁定语句是例外:如果在执行前发生隐式提交,则在执行后不会再次发生。Most of these statements also cause an implicit commit after executing. The intent is to handle each such statement in its own special transaction. Transaction-control and locking statements are exceptions: If an implicit commit occurs before execution, another does not occur after.
定义或修改数据库对象的数据定义语言(DDL)语句。
ALTER EVENT,ALTER FUNCTION,ALTER PROCEDURE,ALTER SERVER,ALTER TABLE,ALTER TABLESPACE,ALTER VIEW,CREATE DATABASE,CREATE EVENT,CREATE FUNCTION,CREATE INDEX,CREATE PROCEDURE,CREATE ROLE,CREATE SERVER,CREATE SPATIAL REFERENCE SYSTEM,CREATE TABLE,CREATE TABLESPACE,CREATE TRIGGER,CREATE VIEW,DROP DATABASE,DROP EVENT,DROP FUNCTION,DROP INDEX,DROP PROCEDURE,DROP ROLE,DROP SERVER,DROP SPATIAL REFERENCE SYSTEM,DROP TABLE,DROP TABLESPACE,DROP TRIGGER,DROP VIEW,INSTALL PLUGIN,RENAME TABLE,TRUNCATE TABLE,UNINSTALL PLUGIN.Data definition language (DDL) statements that define or modify database objects.ALTER EVENT,ALTER FUNCTION,ALTER PROCEDURE,ALTER SERVER,ALTER TABLE,ALTER TABLESPACE,ALTER VIEW,CREATE DATABASE,CREATE EVENT,CREATE FUNCTION,CREATE INDEX,CREATE PROCEDURE,CREATE ROLE,CREATE SERVER,CREATE SPATIAL REFERENCE SYSTEM,CREATE TABLE,CREATE TABLESPACE,CREATE TRIGGER,CREATE VIEW,DROP DATABASE,DROP EVENT,DROP FUNCTION,DROP INDEX,DROP PROCEDURE,DROP ROLE,DROP SERVER,DROP SPATIAL REFERENCE SYSTEM,DROP TABLE,DROP TABLESPACE,DROP TRIGGER,DROP VIEW,INSTALL PLUGIN,RENAME TABLE,TRUNCATE TABLE,UNINSTALL PLUGIN.CREATE TABLE和DROP TABLE语句如果使用TEMPORARY。(这不适用于临时表上的其他操作,如ALTER TABLE和CREATE INDEX,这些操作确实会导致提交。)然而,虽然不发生隐式提交,但该语句也无法回滚,这意味着使用此类语句会导致事务原子性被违反。例如,如果你使用CREATE TEMPORARY TABLE回滚该事务,该表依然存在。CREATE TABLEandDROP TABLEstatements do not commit a transaction if theTEMPORARYkeyword is used. (This does not apply to other operations on temporary tables such asALTER TABLEandCREATE INDEX, which do cause a commit.) However, although no implicit commit occurs, neither can the statement be rolled back, which means that the use of such statements causes transactional atomicity to be violated. For example, if you useCREATE TEMPORARY TABLEand then roll back the transaction, the table remains in existence.CREATE TABLE语句InnoDB作为单一事务处理。这意味着ROLLBACK不会撤销CREATE TABLE语句。TheCREATE TABLEstatement inInnoDBis processed as a single transaction. This means that aROLLBACKfrom the user does not undoCREATE TABLEstatements the user made during that transaction.CREATE TABLE ... SELECT在创建非临时表时,SELECT 会在执行该语句前后引发隐式提交。(对于CREATE TEMPORARY TABLE ... SELECT。)CREATE TABLE ... SELECTcauses an implicit commit before and after the statement is executed when you are creating nontemporary tables. (No commit occurs forCREATE TEMPORARY TABLE ... SELECT.)隐式使用或修改
mysql数据库。ALTER USERCREATE USER,DROP USERGRANT,RENAME USER,REVOKE,SET PASSWORD.Statements that implicitly use or modify tables in themysqldatabase.ALTER USER,CREATE USER,DROP USER,GRANT,RENAME USER,REVOKE,SET PASSWORD.事务控制和锁定语句。
BEGIN,LOCK TABLES,SET autocommit = 1(如果值还不是 1),START TRANSACTION,UNLOCK TABLES.Transaction-control and locking statements.BEGIN,LOCK TABLES,SET autocommit = 1(if the value is not already 1),START TRANSACTION,UNLOCK TABLES.UNLOCK TABLES仅在当前表已被锁定时才提交事务LOCK TABLES以获取非事务性表锁。对于UNLOCK TABLES以下情况不会发生提交FLUSH TABLES WITH READ LOCK因为后面的语句没有获取表级锁。UNLOCK TABLEScommits a transaction only if any tables currently have been locked withLOCK TABLESto acquire nontransactional table locks. A commit does not occur forUNLOCK TABLESfollowingFLUSH TABLES WITH READ LOCKbecause the latter statement does not acquire table-level locks.事务不能嵌套。这是因为当你对任何当前事务执行隐式提交时,
START TRANSACTION语句或其同义Transactions cannot be nested. This is a consequence of the implicit commit performed for any current transaction when you issue aSTART TRANSACTIONstatement or one of its synonyms.导致隐式提交的语句在事务处于
ACTIVE。Statements that cause an implicit commit cannot be used in an XA transaction while the transaction is in anACTIVEstate.BEGIN语句不同于BEGIN关键字的使用,后者以BEGIN ... END复合语句。后者不会导致隐式提交。参见 第 15.6.1 节,“BEGIN ...结束复合语句”。TheBEGINstatement differs from the use of theBEGINkeyword that starts aBEGIN ... ENDcompound statement. The latter does not cause an implicit commit. See Section 15.6.1, “BEGIN ... END Compound Statement”.数据加载语句。
LOAD DATA.LOAD DATA仅对使用NDB存储引擎。Data loading statements.LOAD DATA.LOAD DATAcauses an implicit commit only for tables using theNDBstorage engine.管理语句。
ANALYZE TABLE”,CACHE INDEXCHECK TABLEFLUSH,LOAD INDEX INTO CACHE,OPTIMIZE TABLE,REPAIR TABLE,RESET(但不RESET PERSIST)。Administrative statements.ANALYZE TABLE,CACHE INDEX,CHECK TABLE,FLUSH,LOAD INDEX INTO CACHE,OPTIMIZE TABLE,REPAIR TABLE,RESET(but notRESET PERSIST).Replication 控制语句。
START REPLICA,STOP REPLICA,RESET REPLICA,CHANGE REPLICATION SOURCE TOReplication control statements.START REPLICA,STOP REPLICA,RESET REPLICA,CHANGE REPLICATION SOURCE TO.