有些语句在没有使用commit的时候,事务也会提交,这种情况称为隐式提交,ddl语句,事务语句和管理的语句都会产生隐式提交,这个跟oracle一样的。下面简单测试看看
test>begin;
Query OK, 0 rows affected (0.00 sec)
est>insert into t2 values('bai',22);
Query OK, 1 row affected (0.02 sec)
test>select * from t2;
+------+------+
| name | age |
+------+------+
| xiao | 11 |
| abc | 11 |
| ddd | 10 |
| eee | 11 |
| bai | 22 |
+------+------+
5 rows in set (0.00 sec)
test>create table t5 like t2;
Query OK, 0 rows affected (0.19 sec)
test>select * from t5;
Empty set (0.01 sec)
test>insert into t2 values('xxx',33);
Query OK, 1 row affected (0.02 sec)
.test>rollback;
Query OK, 0 rows affected (0.01 sec)
test>select * from t2;
+------+------+
| name | age |
+------+------+
| xiao | 11 |
| abc | 11 |
| ddd | 10 |
| eee | 11 |
| bai | 22 |
| xxx | 33 |
+------+------+
6 rows in set (0.01 sec)
按正常的理解,应该是只有(‘bai',22)这个记录隐式提交插入了,但是因为mysql是自动提交的,所以在create table t5的时候,事务没了,后面的语句就自动提交了。
est>begin;
Query OK, 0 rows affected (0.01 sec)
test>insert into t2 values('zzz',888);
Query OK, 1 row affected (0.01 sec)
test>grant select on test.* to myadmin@'%';
Query OK, 0 rows affected (0.11 sec)
est>insert into t2 values('vvv',999);
Query OK, 1 row affected (0.02 sec)
test>rollback;
Query OK, 0 rows affected (0.00 sec)
test>select * from t2;
+------+------+
| name | age |
+------+------+
| xiao | 11 |
| abc | 11 |
| ddd | 10 |
| eee | 11 |
| bai | 22 |
| xxx | 33 |
| zzz | 888 |
| vvv | 999 |
+------+------+
8 rows in set (0.00 sec)
看到授权语句也是导致了隐式的提交。