一个简单的试验,你可以看到在 p1中设置的autocommit=0,运行完p1,p2后然后rollback会把p1,p2把插入的记录全部回滚掉。
-
SQL code
-
mysql > create table tab1 ( -> id int primary key -> ) ENGINE = InnoDB ; Query OK, 0 rows affected ( 0.09 sec) mysql > insert into tab1 values ( 1 ); Query OK, 1 row affected ( 0.08 sec) mysql > select * from tab1; + -- --+ | id | + -- --+ | 1 | + -- --+ 1 row in set ( 0.00 sec) mysql > mysql > CREATE PROCEDURE p1 () -> BEGIN -> set @@autocommit = 0 ; -> insert into tab1 values ( 11 ); -> end -> // Query OK, 0 rows affected ( 0.00 sec) mysql > CREATE PROCEDURE p2 () -> begin -> insert into tab1 values ( 12 ); -> end -> // Query OK, 0 rows affected ( 0.00 sec) mysql > delimiter ; mysql > mysql > select @@autocommit ; + -- ------------+ | @@autocommit | + -- ------------+ | 1 | + -- ------------+ 1 row in set ( 0.00 sec) mysql > call p1(); Query OK, 1 row affected ( 0.00 sec) mysql > select @@autocommit ; + -- ------------+ | @@autocommit | + -- ------------+ | 0 | + -- ------------+ 1 row in set ( 0.00 sec) mysql > call p2(); Query OK, 1 row affected ( 0.00 sec) mysql > select * from tab1; + -- --+ | id | + -- --+ | 1 | | 11 | | 12 | + -- --+ 3 rows in set ( 0.00 sec) mysql > rollback ; Query OK, 0 rows affected ( 0.05 sec) mysql > select * from tab1; + -- --+ | id | + -- --+ | 1 | + -- --+ 1 row in set ( 0.00 sec) mysql >