在autocommit=1的情况下,开启一个事务,如果里面有DDL语句,那么事务开始到DDL语句之间的DML语句都会被提交。再开启新的事务。可以从binlog中看出
session语句:
09:26:04 root@localhost:[testdb] mysql.sock>select * from t2;
+——+——–+——-+
| id | course | score |
+——+——–+——-+
| 1 | math | 0 |
| 2 | ch | 0 |
| 3 | eng | 0 |
+——+——–+——-+
3 rows in set (0.00 sec)
09:26:10 root@localhost:[testdb] mysql.sock> begin;
Query OK, 0 rows affected (0.00 sec)
09:26:18 root@localhost:[testdb] mysql.sock> delete from t2 where id=2;
Query OK, 1 row affected (0.05 sec)
09:26:30 root@localhost:[testdb] mysql.sock> alter table t2 drop column score;
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0
09:26:43 root@localhost:[testdb] mysql.sock> delete from t2 where id=3;
Query OK, 1 row affected (0.00 sec)
09:26:53 root@localhost:[testdb] mysql.sock> delete from t2 where id=1;
Query OK, 1 row affected (0.03 sec)
09:27:30 root@localhost:[testdb] mysql.sock>rollback;
Query OK, 0 rows affected (0.00 sec)
09:27:37 root@localhost:[testdb] mysql.sock>select * from t2;
Empty set (0.00 sec)
mysqlbinlog解析:
[ root@zejin240 mysql]# mysqlbinlog –no-defaults -v –base64-output=DECODE-ROWS good.000001
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#160510 9:26:03 server id 4 end_log_pos 120 CRC32 0xfb18f530 Start: binlog v 4, server v 5.6.16-log created 160510 9:26:03 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
# at 120
#160510 9:26:30 server id 4 end_log_pos 194 CRC32 0x4613aabe Query thread_id=1490 exec_time=0 error_code=0
SET TIMESTAMP=1462843590/*!*/;
SET @@session.pseudo_thread_id=1490/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 194
#160510 9:26:30 server id 4 end_log_pos 245 CRC32 0x12aee719 Table_map: `testdb`.`t2` mapped to number 100
# at 245
#160510 9:26:30 server id 4 end_log_pos 292 CRC32 0x42bb4b1e Delete_rows: table id 100 flags: STMT_END_F
### DELETE FROM `testdb`.`t2`
### WHERE
### @1=2
### @2=’ch’
### @3=0
# at 292
#160510 9:26:43 server id 4 end_log_pos 323 CRC32 0x7f4b17a2 Xid = 4683
COMMIT/*!*/;
# at 323
#160510 9:26:43 server id 4 end_log_pos 433 CRC32 0x3da26437 Query thread_id=1490 exec_time=0 error_code=0
use `testdb`/*!*/;
SET TIMESTAMP=1462843603/*!*/;
alter table t2 drop column score
/*!*/;
# at 433
#160510 9:26:53 server id 4 end_log_pos 507 CRC32 0xaf228c7f Query thread_id=1490 exec_time=0 error_code=0
SET TIMESTAMP=1462843613/*!*/;
BEGIN
/*!*/;
# at 507
#160510 9:26:53 server id 4 end_log_pos 557 CRC32 0x98b09e6b Table_map: `testdb`.`t2` mapped to number 108
# at 557
#160510 9:26:53 server id 4 end_log_pos 601 CRC32 0x56abcace Delete_rows: table id 108 flags: STMT_END_F
### DELETE FROM `testdb`.`t2`
### WHERE
### @1=3
### @2=’eng’
# at 601
#160510 9:26:53 server id 4 end_log_pos 632 CRC32 0x41e6e24f Xid = 4754
COMMIT/*!*/;
# at 632
#160510 9:27:30 server id 4 end_log_pos 706 CRC32 0x4916f7a0 Query thread_id=1490 exec_time=0 error_code=0
SET TIMESTAMP=1462843650/*!*/;
BEGIN
/*!*/;
# at 706
#160510 9:27:30 server id 4 end_log_pos 756 CRC32 0x15098e83 Table_map: `testdb`.`t2` mapped to number 108
# at 756
#160510 9:27:30 server id 4 end_log_pos 801 CRC32 0x2bc1b8aa Delete_rows: table id 108 flags: STMT_END_F
### DELETE FROM `testdb`.`t2`
### WHERE
### @1=1
### @2=’math’
# at 801
#160510 9:27:30 server id 4 end_log_pos 832 CRC32 0x9ce9b647 Xid = 4870
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;