最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL執(zhí)行update語句和原數(shù)據(jù)相同會再次執(zhí)行嗎

 更新時間:2019年04月04日 10:10:29   作者:阿里云云棲社區(qū)  
這篇文章主要給大家介紹了關(guān)于MySQL執(zhí)行update語句和原數(shù)據(jù)相同是否會再次執(zhí)行的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用MySQL具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧

背景

本文主要測試MySQL執(zhí)行update語句時,針對與原數(shù)據(jù)(即未修改)相同的update語句會在MySQL內(nèi)部重新執(zhí)行嗎?

測試環(huán)境

  • MySQL5.7.25
  • Centos 7.4

binlog_format為ROW

參數(shù)

root@localhost : (none) 04:53:15> show variables like 'binlog_row_image';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| binlog_row_image | FULL |
+------------------+-------+
1 row in set (0.00 sec)

root@localhost : (none) 04:53:49> show variables like 'binlog_format'; 
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW |
+---------------+-------+
1 row in set (0.00 sec)

root@localhost : test 05:15:14> show variables like 'transaction_isolation';
+-----------------------+-----------------+
| Variable_name  | Value  |
+-----------------------+-----------------+
| transaction_isolation | REPEATABLE-READ |
+-----------------------+-----------------+
1 row in set (0.00 sec)

測試步驟

session1

root@localhost : test 04:49:48> begin;
Query OK, 0 rows affected (0.00 sec)

root@localhost : test 04:49:52> select * from test where id =1;
+----+------+------+------+
| id | sid | mid | name |
+----+------+------+------+
| 1 | 999 | 871 | NW |
+----+------+------+------+
1 row in set (0.00 sec)

root@localhost : (none) 04:54:03> show engine innodb status\Gshow master status\G
...
---
LOG
---
Log sequence number 12090390
Log flushed up to 12090390
Pages flushed up to 12090390
Last checkpoint at 12090381
0 pending log flushes, 0 pending chkp writes
33 log i/o's done, 0.00 log i/o's/second

*************************** 1. row ***************************
  File: mysql-bin.000001
  Position: 154
 Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.00 sec)

session2

root@localhost : test 04:47:45> update test set sid=55 where id =1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

root@localhost : (none) 04:54:03> show engine innodb status\Gshow master status\G
...
---
LOG
---
Log sequence number 12091486
Log flushed up to 12091486
Pages flushed up to 12091486
Last checkpoint at 12091477
0 pending log flushes, 0 pending chkp writes
39 log i/o's done, 0.00 log i/o's/second

*************************** 1. row ***************************
  File: mysql-bin.000001
  Position: 500
 Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 8392d215-4928-11e9-a751-0242ac110002:1
1 row in set (0.00 sec)

session1

root@localhost : test 04:49:57> update test set sid=55 where id =1; 
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

root@localhost : (none) 04:54:03> show engine innodb status\Gshow master status\G
...
---
LOG
---
Log sequence number 12091486
Log flushed up to 12091486
Pages flushed up to 12091486
Last checkpoint at 12091477
0 pending log flushes, 0 pending chkp writes
39 log i/o's done, 0.00 log i/o's/second

*************************** 1. row ***************************
  File: mysql-bin.000001
  Position: 500
 Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 8392d215-4928-11e9-a751-0242ac110002:1
1 row in set (0.00 sec)

root@localhost : test 04:52:05> select * from test where id =1;
+----+------+------+------+
| id | sid | mid | name |
+----+------+------+------+
| 1 | 999 | 871 | NW |
+----+------+------+------+
1 row in set (0.00 sec)

root@localhost : test 04:52:42> commit;
Query OK, 0 rows affected (0.00 sec)

root@localhost : test 04:52:52> select * from test where id =1;
+----+------+------+------+
| id | sid | mid | name |
+----+------+------+------+
| 1 | 55 | 871 | NW |
+----+------+------+------+
1 row in set (0.00 sec)

總結(jié)

binlog_format=rowbinlog_row_image=FULL時,由于MySQL 需要在 binlog 里面記錄所有的字段,所以在讀數(shù)據(jù)的時候就會把所有數(shù)據(jù)都讀出來,那么重復(fù)數(shù)據(jù)的update不會執(zhí)行。即MySQL 調(diào)用了 InnoDB 引擎提供的“修改為 (1,55)”這個接口,但是引擎發(fā)現(xiàn)值與原來相同,不更新,直接返回

binlog_format為STATEMENT

參數(shù)

root@localhost : (none) 04:53:15> show variables like 'binlog_row_image';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| binlog_row_image | FULL |
+------------------+-------+
1 row in set (0.00 sec)

root@localhost : (none) 05:16:08> show variables like 'binlog_format';
+---------------+-----------+
| Variable_name | Value  |
+---------------+-----------+
| binlog_format | STATEMENT |
+---------------+-----------+
1 row in set (0.00 sec)

root@localhost : test 05:15:14> show variables like 'transaction_isolation';
+-----------------------+-----------------+
| Variable_name   | Value   |
+-----------------------+-----------------+
| transaction_isolation | REPEATABLE-READ |
+-----------------------+-----------------+
1 row in set (0.00 sec)

測試步驟

session1

root@localhost : test 05:16:42> begin;
Query OK, 0 rows affected (0.00 sec)

root@localhost : test 05:16:44> select * from test where id =1;
+----+------+------+------+
| id | sid | mid | name |
+----+------+------+------+
| 1 | 111 | 871 | NW |
+----+------+------+------+
1 row in set (0.00 sec)

root@localhost : (none) 05:16:51> show engine innodb status\Gshow master status\G
...
---
LOG
---
Log sequence number 12092582
Log flushed up to 12092582
Pages flushed up to 12092582
Last checkpoint at 12092573
0 pending log flushes, 0 pending chkp writes
45 log i/o's done, 0.00 log i/o's/second

*************************** 1. row ***************************
    File: mysql-bin.000001
   Position: 154
  Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.00 sec)

session2

root@localhost : test 05:18:30> update test set sid=999 where id =1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

root@localhost : (none) 05:18:47> show engine innodb status\Gshow master status\G
...
---
LOG
---
Log sequence number 12093678
Log flushed up to 12093678
Pages flushed up to 12093678
Last checkpoint at 12093669
0 pending log flushes, 0 pending chkp writes
51 log i/o's done, 0.14 log i/o's/second

*************************** 1. row ***************************
    File: mysql-bin.000001
   Position: 438
  Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 8392d215-4928-11e9-a751-0242ac110002:1
1 row in set (0.00 sec)

session1

root@localhost : test 05:16:47> update test set sid=999 where id =1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

root@localhost : (none) 05:20:03> show engine innodb status\Gshow master status\G
...
---
LOG
---
Log sequence number 12094504
Log flushed up to 12094504
Pages flushed up to 12094504
Last checkpoint at 12094495
0 pending log flushes, 0 pending chkp writes
56 log i/o's done, 0.00 log i/o's/second

*************************** 1. row ***************************
    File: mysql-bin.000001
   Position: 438
  Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 8392d215-4928-11e9-a751-0242ac110002:1
1 row in set (0.00 sec)

root@localhost : test 05:19:33> select * from test where id =1;  
+----+------+------+------+
| id | sid | mid | name |
+----+------+------+------+
| 1 | 999 | 871 | NW |
+----+------+------+------+
1 row in set (0.00 sec)

root@localhost : test 05:20:44> commit;
Query OK, 0 rows affected (0.01 sec)

root@localhost : test 05:20:57> select * from test where id =1;
+----+------+------+------+
| id | sid | mid | name |
+----+------+------+------+
| 1 | 999 | 871 | NW |
+----+------+------+------+
1 row in set (0.00 sec)

總結(jié)

在binlog_format=statement和binlog_row_image=FULL時,InnoDB內(nèi)部認真執(zhí)行了update語句,即“把這個值修改成 (1,999)“這個操作,該加鎖的加鎖,該更新的更新。

好了,以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。

相關(guān)文章

  • MySQL實現(xiàn)數(shù)據(jù)插入操作的示例詳解

    MySQL實現(xiàn)數(shù)據(jù)插入操作的示例詳解

    使用MySQL插入數(shù)據(jù)時,可以根據(jù)需求場景選擇合適的插入語句。本文通過給出每個使用場景下的實例來說明數(shù)據(jù)插入的實現(xiàn)過程和方法,希望對大家有所幫助
    2023-02-02
  • 解決mysql服務(wù)器在無操作超時主動斷開連接的情況

    解決mysql服務(wù)器在無操作超時主動斷開連接的情況

    這篇文章主要介紹了解決mysql服務(wù)器在無操作超時主動斷開連接的情況,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • MySQL 百萬級數(shù)據(jù)的4種查詢優(yōu)化方式

    MySQL 百萬級數(shù)據(jù)的4種查詢優(yōu)化方式

    本文講解了MySQL 百萬級數(shù)據(jù)的4種查詢優(yōu)化方式,大家可以根據(jù)自身需求,選擇適合自己的優(yōu)化方式
    2021-06-06
  • Navicat連接MySQL8.0的正確方法(親測有效)

    Navicat連接MySQL8.0的正確方法(親測有效)

    navicat是一款非常強大的數(shù)據(jù)庫可視化操作軟件,程序開發(fā)中經(jīng)常會用到navicat,下面這篇文章主要給大家介紹了關(guān)于Navicat連接MySQL8.0的正確方法,需要的朋友可以參考下
    2022-06-06
  • 總結(jié)12個MySQL慢查詢的原因分析

    總結(jié)12個MySQL慢查詢的原因分析

    這篇文章主要介紹了總結(jié)12個MySQL慢查詢的原因分析,慢查詢,都是因為沒有加索引。如果沒有加索引的話,會導(dǎo)致全表掃描的,更多相關(guān)內(nèi)容需要的朋友可以參考一下
    2022-08-08
  • MySql中如何使用 explain 查詢 SQL 的執(zhí)行計劃

    MySql中如何使用 explain 查詢 SQL 的執(zhí)行計劃

    explain命令是查看查詢優(yōu)化器如何決定執(zhí)行查詢的主要方法。這篇文章重點給大家介紹MySql中如何使用 explain 查詢 SQL 的執(zhí)行計劃,感興趣的朋友一起看看吧
    2018-05-05
  • mysql mycat 中間件安裝與使用

    mysql mycat 中間件安裝與使用

    MyCAT是MySQL中間件,前身是阿里大名鼎鼎的Cobar,Cobar在開源了一段時間后,不了了之。于是MyCAT扛起了這面大旗,在大數(shù)據(jù)時代,其重要性愈發(fā)彰顯。這篇文章主要是MyCAT的入門部署。
    2017-05-05
  • MySQL鎖阻塞的深入分析

    MySQL鎖阻塞的深入分析

    這篇文章主要給大家介紹了關(guān)于MySQL鎖阻塞的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-12-12
  • MySQL的意向共享鎖、意向排它鎖和死鎖

    MySQL的意向共享鎖、意向排它鎖和死鎖

    這篇文章主要介紹了MySQL的意向共享鎖、意向排它鎖和死鎖,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-07-07
  • MySQL UPDATE更新語句精解

    MySQL UPDATE更新語句精解

    mysql update命令的一些詳細用法分析,真是不錯的好東西,建議大家看看。
    2009-03-03

最新評論

拉萨市| 阜城县| 中牟县| 淳安县| 冕宁县| 安西县| 永德县| 绥江县| 瑞安市| 麻城市| 威宁| 孝感市| 浪卡子县| 友谊县| 浮梁县| 常山县| 嘉义市| 托里县| 尚义县| 秦皇岛市| 林州市| 安龙县| 九龙城区| 枣强县| 清新县| 乌海市| 岳池县| 麻江县| 额济纳旗| 新化县| 梁山县| 宁海县| 天全县| 渭南市| 涞水县| 怀仁县| 浦东新区| 榆树市| 武川县| 吉木萨尔县| 蓝田县|