MySQL [mysql]> begin; Query OK, 0rows affected(0.00 sec) MySQL [mysql]> insert tt select null,6,60,null,null,null; ERROR 1665 (HY000): Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
ERROR 1665 (HY000): Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
MySQL [mysql]> show variables like 'innodb_locks_unsafe_for_binlog'; +--------------------------------+-------+ | Variable_name | Value | +--------------------------------+-------+ | innodb_locks_unsafe_for_binlog | ON | +--------------------------------+-------+ 1row in set(0.00 sec) MySQL [mysql]> begin; Query OK, 0rows affected(0.00 sec) MySQL [mysql]> select * from tt where c > 2 for update; +----+------+------+-------+------+------+ | id | c | d | field | f2 | f3 | +----+------+------+-------+------+------+ | 3 | 3 | 30 | NULL | NULL | NULL | | 9 | 5 | 50 | NULL | NULL | NULL | | 20 | 4 | 90 | NULL | NULL | NULL | +----+------+------+-------+------+------+ 3rows in set(0.00 sec) MySQL [mysql]> update tt set d = 0 where c > 2; Query OK, 3rows affected(0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 MySQL [mysql]> select * from tt where c > 2; +----+------+------+-------+------+------+ | id | c | d | field | f2 | f3 | +----+------+------+-------+------+------+ | 3 | 3 | 0 | NULL | NULL | NULL | | 9 | 5 | 0 | NULL | NULL | NULL | | 20 | 4 | 0 | NULL | NULL | NULL | | 25 | 6 | 60 | NULL | NULL | NULL | +----+------+------+-------+------+------+ 4rows in set(0.00 sec) MySQL [mysql]> commit;
sessionB:
1 2 3 4 5 6 7 8
MySQL [(none)]> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
SET TIMESTAMP=1598347030/*!*/; BEGIN /*!*/; # at 1708 # at 1740 #20082517:17:10 server id 1 end_log_pos 1740 CRC32 0xe0159005 Intvar SET INSERT_ID=25/*!*/; #20082517:17:10 server id 1 end_log_pos 1857 CRC32 0xc851009c Query thread_id=4 exec_time=0 error_code=0 SET TIMESTAMP=1598347030/*!*/; insert tt select null,6,60,null,null,null /*!*/; # at 1857 #20082517:17:10 server id 1 end_log_pos 1888 CRC32 0x9f72707d Xid = 142 COMMIT/*!*/; # at 1888 #20082517:17:54 server id 1 end_log_pos 1953 CRC32 0x1b7f81f5 Anonymous_GTID last_committed=5 sequence_number=7 rbr_only=no SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/; # at 1953 #20082517:16:39 server id 1 end_log_pos 2034 CRC32 0xc51fd871 Query thread_id=2 exec_time=0 error_code=0 SET TIMESTAMP=1598346999/*!*/; BEGIN /*!*/; # at 2034 #20082517:16:39 server id 1 end_log_pos 2141 CRC32 0xa64310b0 Query thread_id=2 exec_time=0 error_code=0 SET TIMESTAMP=1598346999/*!*/; update tt set d = 0 where c > 2
sessionA后提交的,如果根据binlog恢复数据或者从库更新:
1 insert tt select null,6,60,null,null,null
2 update tt set d = 0 where c > 2
就得不到主库的结果了:
1 2 3 4 5 6 7 8 9
MySQL [mysql]> select * from tt where c > 2; +----+------+------+-------+------+------+ | id | c | d | field | f2 | f3 | +----+------+------+-------+------+------+ | 3 | 3 | 0 | NULL | NULL | NULL | | 9 | 5 | 0 | NULL | NULL | NULL | | 20 | 4 | 0 | NULL | NULL | NULL | | 25 | 6 | 60 | NULL | NULL | NULL | +----+------+------+-------+------+------+
MySQL [mysql]> begin; Query OK, 0rows affected(0.00 sec) MySQL [mysql]> select * from tt where id = 20 for update; +----+------+------+-------+------+------+ | id | c | d | field | f2 | f3 | +----+------+------+-------+------+------+ | 20 | 4 | 90 | NULL | NULL | NULL | +----+------+------+-------+------+------+ 1row in set(0.01 sec)