tx_isolation=READ-COMMITTED +binlog_format=STATEMENT产生的问题


mysql的隔离级:

隔离级别                    
未提交读(Read uncommitted)
已提交读(Read committed)  
可重复读(Repeatable read) 
可串行化(Serializable )   


binlog_format格式有

STATEMENT :每一条会修改数据的 SQL 都会记录到 master 的 bin-log 中。slave 在复制的时候 SQL 进程会解析成和原来 master 端执行过的相同的 SQL 再次执行。
ROW  :日志中会记录成每一行数据被修改的形式,然后在 slave 端再对相同的数据进行修改。
MIXED : Statement 和 Row  混合


set global tx_isolation=1;
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

都没有问题


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值