mysql的隔离级:
隔离级别
未提交读(Read uncommitted)
已提交读(Read committed)
可重复读(Repeatable read)
可串行化(Serializable )
binlog_format格式有
STATEMENT :每一条会修改数据的 SQL 都会记录到 master 的 bin-log 中。slave 在复制的时候 SQL 进程会解析成和原来 master 端执行过的相同的 SQL 再次执行。
ROW :日志中会记录成每一行数据被修改的形式,然后在 slave 端再对相同的数据进行修改。
MIXED : Statement 和 Row 混合
mysql> select @@global.tx_isolation;
+-----------------------+
| @@global.tx_isolation |
+-----------------------+
| READ-COMMITTED |
+-----------------------+
1 row in set (0.00 sec)
mysql> show variables like 'binlog_format%';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| binlog_format | STATEMENT |
+---------------+-----------+
1 row in set (0.01 sec)
mysql> select * From t;
+------+------+
| id | a |
+------+------+
| 32 | a |
| 21 | a |
+------+------+
mysql> update t set a='b';
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> set global tx_isolation=2;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@global.tx_isolation;
+-----------------------+
| @@global.tx_isolation |
+-----------------------+
| REPEATABLE-READ |
+-----------------------+
1 row in set (0.00 sec)
exit
重新打开一个session
mysql> update t set a='b';
Query OK, 2 rows affected (0.05 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select * from t;
+------+------+
| id | a |
+------+------+
| 32 | b |
| 21 | b |
+------+------+
2 rows in set (0.00 sec)
或者修改binlog_format=mixed
mysql> select @@binlog_format;
+-----------------+
| @@binlog_format |
+-----------------+
| MIXED |
+-----------------+
1 row in set (0.00 sec)
mysql> update t set a='d';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select * from t;
+------+------+
| id | a |
+------+------+
| 32 | d |
| 21 | d |
+------+------+
2 rows in set (0.00 sec)
结论: 隔离级别改为下列两种方式都是可以的
tx_isolation=Read committed
binlog_format=mixed
或者是
tx_isolation= REPEATABLE-READ
binlog_format=STATEMENT
都没有问题