同一个事务内修改两次,第二次改回原状会不会产生binlog,改前改后相同会不会产生binlog


实验一

1 修改前表内容

mysql> select * from user;
+----------------------------+------+------------+-------+-------+
| gmt_create                 | name | gmt_modify | gmt_4 | gmt_3 |
+----------------------------+------+------------+-------+-------+
| 2015-12-12 12:12:12.000000 | aaa  | NULL       | NULL  | NULL  |
+----------------------------+------+------------+-------+-------+
1 row in set (0.00 sec)
 

show master status; 的结果,位点是 1655;

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000061 |     1655 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
2 执行update操作,但是改前改后的值相同


conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
String sqlDiff = "update user.user set name='aaa';";
stmt.execute(sqlDiff);
conn.commit();

3 执行后执行show master status;结果没有变化-- 说明并没有产生binlog

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000061 |     1655 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

实验二

1 和实验一相同

2 执行脚本

conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
String sqlSame = "update user.user set name='ccc';";
String sqlDiff = "update user.user set name='aaa';";
stmt.execute(sqlSame);
stmt.execute(sqlDiff);
3 在mysql上执行show master status, binlog的位点发生了变化,从1655变成1968

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000061 |     1968 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

4 执行mysqlbinlog工具,查看binlog文件内容

mysqlbinlog --host 127.0.0.1  -P3306 -R -uroot   -proot  mysql-bin.000061 -j 4 --base64-output=decode-rows --verbose

查看结果,产生的两次变更都记录到binlog里面。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值