14

MySQL中,当update修改数据与原数据相同时会再次执行吗?

 3 years ago
source link: http://mp.weixin.qq.com/s?__biz=MzU2NjIzNDk5NQ%3D%3D&%3Bmid=2247491561&%3Bidx=1&%3Bsn=f5945af81fff6fdd97139c6b68e00c41
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

收录于话题

点击上方 匠心零度 ,选择“ 设为星标

做积极的人,而不是积极废人

feUB3em.jpg!mobile

来源:https://yq.aliyun.com/articles/694162

一、背景

本文主要测试MySQL执行update语句时,针对与原数据(即未修改)相同的update语句会在MySQL内部重新执行吗?

二、测试环境

MySQL5.7.25

Centos 7.4

三、binlog_format为ROW

1、参数

A3MZzmY.png!mobile

2、测试步骤

session1

6rABRrZ.jpg!mobile

session2

ZZNnueb.jpg!mobile

session1

uUfueqM.jpg!mobile

3、总结

binlog_format=row 和binlog_row_image=FULL时, 由于MySQL 需要在 binlog 里面记录所有的字段,所以在读数据的时候就会把所有数据都读出来,那么 重复数据的update不会执行 。即MySQL 调用了 InnoDB 引擎提供的“修改为 (1,55)”这个接口,但是引擎发现值与原来相同,不更新,直接返回。

四、binlog_format为STATEMENT

1、参数

2MjeaiZ.png!mobile

2、测试步骤

session1

qIRRFn.jpg!mobile

session2

RRNfaqa.jpg!mobile

session1

jEFNRn.jpg!mobile

3、总结

在binlog_format=statement 和binlog_row_image=FULL时, InnoDB内部认真执行了update语句,即“把这个值修改成 (1,999)“这个操作,该加锁的加锁,该更新的更新。

END

如果读完觉得有收获的话,欢迎点【好看】,关注【匠心零度】,查阅更多精彩历史!!!

nmqYriz.gif!mobile

让我“ 好看 ”  bYreamJ.gif!mobile


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK