MySQL UPDATE

环境说明

MySQL8.0 image.png

1、binlog_formatROW

A.查看相关参数值

  1. mysql> show variables like 'binlog_row_image';
  2. +------------------+-------+
  3. | Variable_name | Value |
  4. +------------------+-------+
  5. | binlog_row_image | FULL |
  6. +------------------+-------+
  7. 1 row in set, 1 warning (0.00 sec)
  8. mysql> show variables like 'binlog_format';
  9. +---------------+-------+
  10. | Variable_name | Value |
  11. +---------------+-------+
  12. | binlog_format | ROW |
  13. +---------------+-------+
  14. 1 row in set, 1 warning (0.00 sec)
  15. mysql> show variables like 'transaction_isolation';
  16. +-----------------------+-----------------+
  17. | Variable_name | Value |
  18. +-----------------------+-----------------+
  19. | transaction_isolation | REPEATABLE-READ |
  20. +-----------------------+-----------------+
  21. 1 row in set, 1 warning (0.00 sec)

image.png

B.测试步骤

session1:select

  1. mysql> use test;
  2. Database changed
  3. mysql> select * from user where id = 1;
  4. +----+---------+-----+------+---------------------+-----------+
  5. | id | user_id | age | name | login_time | address |
  6. +----+---------+-----+------+---------------------+-----------+
  7. | 1 | 11 | 18 | Fc | 2020-07-23 22:16:57 | 北京市 |
  8. +----+---------+-----+------+---------------------+-----------+
  9. 1 row in set (0.00 sec)
  10. mysql> show engine innodb status\Gshow master status\G
  11. *************************** 1. row ***************************
  12. Type: InnoDB
  13. Name:
  14. Status:
  15. =====================================
  16. 2020-07-24 14:17:04 0x3b50 INNODB MONITOR OUTPUT
  17. =====================================
  18. Per second averages calculated from the last 2 seconds
  19. -----------------
  20. BACKGROUND THREAD
  21. -----------------
  22. srv_master_thread loops: 17 srv_active, 0 srv_shutdown, 23290 srv_idle
  23. srv_master_thread log flush and writes: 0
  24. ----------
  25. SEMAPHORES
  26. ----------
  27. OS WAIT ARRAY INFO: reservation count 12
  28. OS WAIT ARRAY INFO: signal count 11
  29. RW-shared spins 0, rounds 0, OS waits 0
  30. RW-excl spins 125, rounds 242, OS waits 1
  31. RW-sx spins 0, rounds 0, OS waits 0
  32. Spin rounds per wait: 0.00 RW-shared, 1.94 RW-excl, 0.00 RW-sx
  33. ------------
  34. TRANSACTIONS
  35. ------------
  36. Trx id counter 16774
  37. Purge done for trx's n:o < 16773 undo n:o < 0 state: running but idle
  38. History list length 54
  39. LIST OF TRANSACTIONS FOR EACH SESSION:
  40. ---TRANSACTION 283929911700120, not started
  41. 0 lock struct(s), heap size 1136, 0 row lock(s)
  42. ---TRANSACTION 283929911699248, not started
  43. 0 lock struct(s), heap size 1136, 0 row lock(s)
  44. --------
  45. FILE I/O
  46. --------
  47. I/O thread 0 state: wait Windows aio (insert buffer thread)
  48. I/O thread 1 state: wait Windows aio (log thread)
  49. I/O thread 2 state: wait Windows aio (read thread)
  50. I/O thread 3 state: wait Windows aio (read thread)
  51. I/O thread 4 state: wait Windows aio (read thread)
  52. I/O thread 5 state: wait Windows aio (read thread)
  53. I/O thread 6 state: wait Windows aio (write thread)
  54. I/O thread 7 state: wait Windows aio (write thread)
  55. I/O thread 8 state: wait Windows aio (write thread)
  56. I/O thread 9 state: wait Windows aio (write thread)
  57. Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
  58. ibuf aio reads:, log i/o's:, sync i/o's:
  59. Pending flushes (fsync) log: 0; buffer pool: 0
  60. 1065 OS file reads, 1161 OS file writes, 330 OS fsyncs
  61. 0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
  62. -------------------------------------
  63. INSERT BUFFER AND ADAPTIVE HASH INDEX
  64. -------------------------------------
  65. Ibuf: size 1, free list len 0, seg size 2, 0 merges
  66. merged operations:
  67. insert 0, delete mark 0, delete 0
  68. discarded operations:
  69. insert 0, delete mark 0, delete 0
  70. Hash table size 34679, node heap has 0 buffer(s)
  71. Hash table size 34679, node heap has 2 buffer(s)
  72. Hash table size 34679, node heap has 0 buffer(s)
  73. Hash table size 34679, node heap has 0 buffer(s)
  74. Hash table size 34679, node heap has 0 buffer(s)
  75. Hash table size 34679, node heap has 1 buffer(s)
  76. Hash table size 34679, node heap has 2 buffer(s)
  77. Hash table size 34679, node heap has 6 buffer(s)
  78. 0.00 hash searches/s, 0.00 non-hash searches/s
  79. ---
  80. LOG
  81. ---
  82. Log sequence number 34446419
  83. Log buffer assigned up to 34446419
  84. Log buffer completed up to 34446419
  85. Log written up to 34446419
  86. Log flushed up to 34446419
  87. Added dirty pages up to 34446419
  88. Pages flushed up to 34446419
  89. Last checkpoint at 34446419
  90. 330 log i/o's done, 0.00 log i/o's/second
  91. ----------------------
  92. BUFFER POOL AND MEMORY
  93. ----------------------
  94. Total large memory allocated 137363456
  95. Dictionary memory allocated 429080
  96. Buffer pool size 8192
  97. Free buffers 6969
  98. Database pages 1212
  99. Old database pages 458
  100. Modified db pages 0
  101. Pending reads 0
  102. Pending writes: LRU 0, flush list 0, single page 0
  103. Pages made young 1, not young 0
  104. 0.00 youngs/s, 0.00 non-youngs/s
  105. Pages read 1042, created 170, written 723
  106. 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
  107. No buffer pool page gets since the last printout
  108. Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
  109. LRU len: 1212, unzip_LRU len: 0
  110. I/O sum[0]:cur[0], unzip sum[0]:cur[0]
  111. --------------
  112. ROW OPERATIONS
  113. --------------
  114. 0 queries inside InnoDB, 0 queries in queue
  115. 0 read views open inside InnoDB
  116. Process ID=472, Main thread ID=00000000000039CC , state=sleeping
  117. Number of rows inserted 246, updated 426, deleted 194, read 33839
  118. 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
  119. ----------------------------
  120. END OF INNODB MONITOR OUTPUT
  121. ============================
  122. 1 row in set (0.00 sec)
  123. *************************** 1. row ***************************
  124. File: binlog.000021
  125. Position: 3434
  126. Binlog_Do_DB:
  127. Binlog_Ignore_DB:
  128. Executed_Gtid_Set:
  129. 1 row in set (0.00 sec)
  130. mysql>

image.png

session2:update

  1. mysql> update user set user_id = 11 where id = 1;
  2. Query OK, 0 rows affected (0.00 sec)
  3. Rows matched: 1 Changed: 0 Warnings: 0
  4. mysql> show engine innodb status\Gshow master status\G
  5. *************************** 1. row ***************************
  6. Type: InnoDB
  7. Name:
  8. Status:
  9. =====================================
  10. 2020-07-24 14:21:11 0x3b50 INNODB MONITOR OUTPUT
  11. =====================================
  12. Per second averages calculated from the last 3 seconds
  13. -----------------
  14. BACKGROUND THREAD
  15. -----------------
  16. srv_master_thread loops: 17 srv_active, 0 srv_shutdown, 23537 srv_idle
  17. srv_master_thread log flush and writes: 0
  18. ----------
  19. SEMAPHORES
  20. ----------
  21. OS WAIT ARRAY INFO: reservation count 12
  22. OS WAIT ARRAY INFO: signal count 11
  23. RW-shared spins 0, rounds 0, OS waits 0
  24. RW-excl spins 125, rounds 242, OS waits 1
  25. RW-sx spins 0, rounds 0, OS waits 0
  26. Spin rounds per wait: 0.00 RW-shared, 1.94 RW-excl, 0.00 RW-sx
  27. ------------
  28. TRANSACTIONS
  29. ------------
  30. Trx id counter 16775
  31. Purge done for trx's n:o < 16773 undo n:o < 0 state: running but idle
  32. History list length 54
  33. LIST OF TRANSACTIONS FOR EACH SESSION:
  34. ---TRANSACTION 283929911700120, not started
  35. 0 lock struct(s), heap size 1136, 0 row lock(s)
  36. ---TRANSACTION 283929911699248, not started
  37. 0 lock struct(s), heap size 1136, 0 row lock(s)
  38. --------
  39. FILE I/O
  40. --------
  41. I/O thread 0 state: wait Windows aio (insert buffer thread)
  42. I/O thread 1 state: wait Windows aio (log thread)
  43. I/O thread 2 state: wait Windows aio (read thread)
  44. I/O thread 3 state: wait Windows aio (read thread)
  45. I/O thread 4 state: wait Windows aio (read thread)
  46. I/O thread 5 state: wait Windows aio (read thread)
  47. I/O thread 6 state: wait Windows aio (write thread)
  48. I/O thread 7 state: wait Windows aio (write thread)
  49. I/O thread 8 state: wait Windows aio (write thread)
  50. I/O thread 9 state: wait Windows aio (write thread)
  51. Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
  52. ibuf aio reads:, log i/o's:, sync i/o's:
  53. Pending flushes (fsync) log: 0; buffer pool: 0
  54. 1065 OS file reads, 1161 OS file writes, 330 OS fsyncs
  55. 0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
  56. -------------------------------------
  57. INSERT BUFFER AND ADAPTIVE HASH INDEX
  58. -------------------------------------
  59. Ibuf: size 1, free list len 0, seg size 2, 0 merges
  60. merged operations:
  61. insert 0, delete mark 0, delete 0
  62. discarded operations:
  63. insert 0, delete mark 0, delete 0
  64. Hash table size 34679, node heap has 0 buffer(s)
  65. Hash table size 34679, node heap has 2 buffer(s)
  66. Hash table size 34679, node heap has 0 buffer(s)
  67. Hash table size 34679, node heap has 0 buffer(s)
  68. Hash table size 34679, node heap has 0 buffer(s)
  69. Hash table size 34679, node heap has 1 buffer(s)
  70. Hash table size 34679, node heap has 2 buffer(s)
  71. Hash table size 34679, node heap has 6 buffer(s)
  72. 0.00 hash searches/s, 0.00 non-hash searches/s
  73. ---
  74. LOG
  75. ---
  76. Log sequence number 34446419
  77. Log buffer assigned up to 34446419
  78. Log buffer completed up to 34446419
  79. Log written up to 34446419
  80. Log flushed up to 34446419
  81. Added dirty pages up to 34446419
  82. Pages flushed up to 34446419
  83. Last checkpoint at 34446419
  84. 330 log i/o's done, 0.00 log i/o's/second
  85. ----------------------
  86. BUFFER POOL AND MEMORY
  87. ----------------------
  88. Total large memory allocated 137363456
  89. Dictionary memory allocated 429080
  90. Buffer pool size 8192
  91. Free buffers 6969
  92. Database pages 1212
  93. Old database pages 458
  94. Modified db pages 0
  95. Pending reads 0
  96. Pending writes: LRU 0, flush list 0, single page 0
  97. Pages made young 1, not young 0
  98. 0.00 youngs/s, 0.00 non-youngs/s
  99. Pages read 1042, created 170, written 723
  100. 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
  101. No buffer pool page gets since the last printout
  102. Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
  103. LRU len: 1212, unzip_LRU len: 0
  104. I/O sum[0]:cur[0], unzip sum[0]:cur[0]
  105. --------------
  106. ROW OPERATIONS
  107. --------------
  108. 0 queries inside InnoDB, 0 queries in queue
  109. 0 read views open inside InnoDB
  110. Process ID=472, Main thread ID=00000000000039CC , state=sleeping
  111. Number of rows inserted 246, updated 426, deleted 194, read 33840
  112. 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
  113. ----------------------------
  114. END OF INNODB MONITOR OUTPUT
  115. ============================
  116. 1 row in set (0.00 sec)
  117. *************************** 1. row ***************************
  118. File: binlog.000021
  119. Position: 3434
  120. Binlog_Do_DB:
  121. Binlog_Ignore_DB:
  122. Executed_Gtid_Set:
  123. 1 row in set (0.00 sec)
  124. mysql>

image.png

session3:update

  1. mysql> update user set user_id = 11 where id = 1;
  2. Query OK, 0 rows affected (0.00 sec)
  3. Rows matched: 1 Changed: 0 Warnings: 0
  4. mysql> show engine innodb status\Gshow master status\G
  5. *************************** 1. row ***************************
  6. Type: InnoDB
  7. Name:
  8. Status:
  9. =====================================
  10. 2020-07-24 14:28:37 0x3b50 INNODB MONITOR OUTPUT
  11. =====================================
  12. Per second averages calculated from the last 19 seconds
  13. -----------------
  14. BACKGROUND THREAD
  15. -----------------
  16. srv_master_thread loops: 17 srv_active, 0 srv_shutdown, 23983 srv_idle
  17. srv_master_thread log flush and writes: 0
  18. ----------
  19. SEMAPHORES
  20. ----------
  21. OS WAIT ARRAY INFO: reservation count 12
  22. OS WAIT ARRAY INFO: signal count 11
  23. RW-shared spins 0, rounds 0, OS waits 0
  24. RW-excl spins 125, rounds 242, OS waits 1
  25. RW-sx spins 0, rounds 0, OS waits 0
  26. Spin rounds per wait: 0.00 RW-shared, 1.94 RW-excl, 0.00 RW-sx
  27. ------------
  28. TRANSACTIONS
  29. ------------
  30. Trx id counter 16776
  31. Purge done for trx's n:o < 16773 undo n:o < 0 state: running but idle
  32. History list length 54
  33. LIST OF TRANSACTIONS FOR EACH SESSION:
  34. ---TRANSACTION 283929911700120, not started
  35. 0 lock struct(s), heap size 1136, 0 row lock(s)
  36. ---TRANSACTION 283929911699248, not started
  37. 0 lock struct(s), heap size 1136, 0 row lock(s)
  38. --------
  39. FILE I/O
  40. --------
  41. I/O thread 0 state: wait Windows aio (insert buffer thread)
  42. I/O thread 1 state: wait Windows aio (log thread)
  43. I/O thread 2 state: wait Windows aio (read thread)
  44. I/O thread 3 state: wait Windows aio (read thread)
  45. I/O thread 4 state: wait Windows aio (read thread)
  46. I/O thread 5 state: wait Windows aio (read thread)
  47. I/O thread 6 state: wait Windows aio (write thread)
  48. I/O thread 7 state: wait Windows aio (write thread)
  49. I/O thread 8 state: wait Windows aio (write thread)
  50. I/O thread 9 state: wait Windows aio (write thread)
  51. Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
  52. ibuf aio reads:, log i/o's:, sync i/o's:
  53. Pending flushes (fsync) log: 0; buffer pool: 0
  54. 1065 OS file reads, 1161 OS file writes, 330 OS fsyncs
  55. 0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
  56. -------------------------------------
  57. INSERT BUFFER AND ADAPTIVE HASH INDEX
  58. -------------------------------------
  59. Ibuf: size 1, free list len 0, seg size 2, 0 merges
  60. merged operations:
  61. insert 0, delete mark 0, delete 0
  62. discarded operations:
  63. insert 0, delete mark 0, delete 0
  64. Hash table size 34679, node heap has 0 buffer(s)
  65. Hash table size 34679, node heap has 2 buffer(s)
  66. Hash table size 34679, node heap has 0 buffer(s)
  67. Hash table size 34679, node heap has 0 buffer(s)
  68. Hash table size 34679, node heap has 0 buffer(s)
  69. Hash table size 34679, node heap has 1 buffer(s)
  70. Hash table size 34679, node heap has 2 buffer(s)
  71. Hash table size 34679, node heap has 6 buffer(s)
  72. 0.00 hash searches/s, 0.05 non-hash searches/s
  73. ---
  74. LOG
  75. ---
  76. Log sequence number 34446419
  77. Log buffer assigned up to 34446419
  78. Log buffer completed up to 34446419
  79. Log written up to 34446419
  80. Log flushed up to 34446419
  81. Added dirty pages up to 34446419
  82. Pages flushed up to 34446419
  83. Last checkpoint at 34446419
  84. 330 log i/o's done, 0.00 log i/o's/second
  85. ----------------------
  86. BUFFER POOL AND MEMORY
  87. ----------------------
  88. Total large memory allocated 137363456
  89. Dictionary memory allocated 429080
  90. Buffer pool size 8192
  91. Free buffers 6969
  92. Database pages 1212
  93. Old database pages 458
  94. Modified db pages 0
  95. Pending reads 0
  96. Pending writes: LRU 0, flush list 0, single page 0
  97. Pages made young 1, not young 0
  98. 0.00 youngs/s, 0.00 non-youngs/s
  99. Pages read 1042, created 170, written 723
  100. 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
  101. Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
  102. Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
  103. LRU len: 1212, unzip_LRU len: 0
  104. I/O sum[0]:cur[0], unzip sum[0]:cur[0]
  105. --------------
  106. ROW OPERATIONS
  107. --------------
  108. 0 queries inside InnoDB, 0 queries in queue
  109. 0 read views open inside InnoDB
  110. Process ID=472, Main thread ID=00000000000039CC , state=sleeping
  111. Number of rows inserted 246, updated 426, deleted 194, read 33841
  112. 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.05 reads/s
  113. ----------------------------
  114. END OF INNODB MONITOR OUTPUT
  115. ============================
  116. 1 row in set (0.00 sec)
  117. *************************** 1. row ***************************
  118. File: binlog.000021
  119. Position: 3434
  120. Binlog_Do_DB:
  121. Binlog_Ignore_DB:
  122. Executed_Gtid_Set:
  123. 1 row in set (0.00 sec)
  124. mysql>

image.png
对比session2中的upadted发现updated一致

C.总结

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

2、binlog_formatSTATEMENT

A.查看相关参数值

  1. mysql> set session binlog_format = statement;
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> show variables like 'binlog_row_image';
  4. +------------------+-------+
  5. | Variable_name | Value |
  6. +------------------+-------+
  7. | binlog_row_image | FULL |
  8. +------------------+-------+
  9. 1 row in set, 1 warning (0.00 sec)
  10. mysql> show variables like 'binlog_format';
  11. +---------------+-----------+
  12. | Variable_name | Value |
  13. +---------------+-----------+
  14. | binlog_format | STATEMENT |
  15. +---------------+-----------+
  16. 1 row in set, 1 warning (0.00 sec)
  17. mysql> show variables like 'transaction_isolation';
  18. +-----------------------+-----------------+
  19. | Variable_name | Value |
  20. +-----------------------+-----------------+
  21. | transaction_isolation | REPEATABLE-READ |
  22. +-----------------------+-----------------+
  23. 1 row in set, 1 warning (0.00 sec)
  24. mysql>

image.png

B.测试步骤

session1:select

  1. mysql> select * from user where id = 1;
  2. +----+---------+-----+------+---------------------+-----------+
  3. | id | user_id | age | name | login_time | address |
  4. +----+---------+-----+------+---------------------+-----------+
  5. | 1 | 11 | 18 | Fc | 2020-07-23 22:16:57 | 北京市 |
  6. +----+---------+-----+------+---------------------+-----------+
  7. 1 row in set (0.00 sec)
  8. mysql> show engine innodb status\Gshow master status\G
  9. *************************** 1. row ***************************
  10. Type: InnoDB
  11. Name:
  12. Status:
  13. =====================================
  14. 2020-07-24 15:04:07 0x3b50 INNODB MONITOR OUTPUT
  15. =====================================
  16. Per second averages calculated from the last 56 seconds
  17. -----------------
  18. BACKGROUND THREAD
  19. -----------------
  20. srv_master_thread loops: 21 srv_active, 0 srv_shutdown, 26107 srv_idle
  21. srv_master_thread log flush and writes: 0
  22. ----------
  23. SEMAPHORES
  24. ----------
  25. OS WAIT ARRAY INFO: reservation count 12
  26. OS WAIT ARRAY INFO: signal count 11
  27. RW-shared spins 0, rounds 0, OS waits 0
  28. RW-excl spins 125, rounds 242, OS waits 1
  29. RW-sx spins 0, rounds 0, OS waits 0
  30. Spin rounds per wait: 0.00 RW-shared, 1.94 RW-excl, 0.00 RW-sx
  31. ------------
  32. TRANSACTIONS
  33. ------------
  34. Trx id counter 16847
  35. Purge done for trx's n:o < 16779 undo n:o < 0 state: running but idle
  36. History list length 87
  37. LIST OF TRANSACTIONS FOR EACH SESSION:
  38. ---TRANSACTION 283929911699248, not started
  39. 0 lock struct(s), heap size 1136, 0 row lock(s)
  40. ---TRANSACTION 283929911700120, not started
  41. 0 lock struct(s), heap size 1136, 0 row lock(s)
  42. --------
  43. FILE I/O
  44. --------
  45. I/O thread 0 state: wait Windows aio (insert buffer thread)
  46. I/O thread 1 state: wait Windows aio (log thread)
  47. I/O thread 2 state: wait Windows aio (read thread)
  48. I/O thread 3 state: wait Windows aio (read thread)
  49. I/O thread 4 state: wait Windows aio (read thread)
  50. I/O thread 5 state: wait Windows aio (read thread)
  51. I/O thread 6 state: wait Windows aio (write thread)
  52. I/O thread 7 state: wait Windows aio (write thread)
  53. I/O thread 8 state: wait Windows aio (write thread)
  54. I/O thread 9 state: wait Windows aio (write thread)
  55. Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
  56. ibuf aio reads:, log i/o's:, sync i/o's:
  57. Pending flushes (fsync) log: 0; buffer pool: 0
  58. 1122 OS file reads, 1306 OS file writes, 400 OS fsyncs
  59. 0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
  60. -------------------------------------
  61. INSERT BUFFER AND ADAPTIVE HASH INDEX
  62. -------------------------------------
  63. Ibuf: size 1, free list len 0, seg size 2, 0 merges
  64. merged operations:
  65. insert 0, delete mark 0, delete 0
  66. discarded operations:
  67. insert 0, delete mark 0, delete 0
  68. Hash table size 34679, node heap has 1 buffer(s)
  69. Hash table size 34679, node heap has 2 buffer(s)
  70. Hash table size 34679, node heap has 0 buffer(s)
  71. Hash table size 34679, node heap has 0 buffer(s)
  72. Hash table size 34679, node heap has 1 buffer(s)
  73. Hash table size 34679, node heap has 1 buffer(s)
  74. Hash table size 34679, node heap has 2 buffer(s)
  75. Hash table size 34679, node heap has 7 buffer(s)
  76. 0.00 hash searches/s, 0.00 non-hash searches/s
  77. ---
  78. LOG
  79. ---
  80. Log sequence number 34458677
  81. Log buffer assigned up to 34458677
  82. Log buffer completed up to 34458677
  83. Log written up to 34458677
  84. Log flushed up to 34458677
  85. Added dirty pages up to 34458677
  86. Pages flushed up to 34458677
  87. Last checkpoint at 34458677
  88. 392 log i/o's done, 0.00 log i/o's/second
  89. ----------------------
  90. BUFFER POOL AND MEMORY
  91. ----------------------
  92. Total large memory allocated 137363456
  93. Dictionary memory allocated 473442
  94. Buffer pool size 8192
  95. Free buffers 6911
  96. Database pages 1267
  97. Old database pages 487
  98. Modified db pages 0
  99. Pending reads 0
  100. Pending writes: LRU 0, flush list 0, single page 0
  101. Pages made young 1, not young 0
  102. 0.00 youngs/s, 0.00 non-youngs/s
  103. Pages read 1097, created 170, written 797
  104. 0.00 reads/s, 0.00 creates/s, 0.00 writes/s
  105. No buffer pool page gets since the last printout
  106. Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
  107. LRU len: 1267, unzip_LRU len: 0
  108. I/O sum[0]:cur[0], unzip sum[0]:cur[0]
  109. --------------
  110. ROW OPERATIONS
  111. --------------
  112. 0 queries inside InnoDB, 0 queries in queue
  113. 0 read views open inside InnoDB
  114. Process ID=472, Main thread ID=00000000000039CC , state=sleeping
  115. Number of rows inserted 250, updated 459, deleted 194, read 53826
  116. 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
  117. ----------------------------
  118. END OF INNODB MONITOR OUTPUT
  119. ============================
  120. 1 row in set (0.00 sec)
  121. *************************** 1. row ***************************
  122. File: binlog.000021
  123. Position: 3434
  124. Binlog_Do_DB:
  125. Binlog_Ignore_DB:
  126. Executed_Gtid_Set:
  127. 1 row in set (0.00 sec)

image.png

session2:update

  1. mysql> update user set user_id = 111 where id = 1;
  2. Query OK, 1 row affected (0.01 sec)
  3. Rows matched: 1 Changed: 1 Warnings: 0
  4. mysql> show engine innodb status\Gshow master status\G
  5. *************************** 1. row ***************************
  6. Type: InnoDB
  7. Name:
  8. Status:
  9. =====================================
  10. 2020-07-24 15:12:04 0x3b50 INNODB MONITOR OUTPUT
  11. =====================================
  12. Per second averages calculated from the last 34 seconds
  13. -----------------
  14. BACKGROUND THREAD
  15. -----------------
  16. srv_master_thread loops: 24 srv_active, 0 srv_shutdown, 26580 srv_idle
  17. srv_master_thread log flush and writes: 0
  18. ----------
  19. SEMAPHORES
  20. ----------
  21. OS WAIT ARRAY INFO: reservation count 18
  22. OS WAIT ARRAY INFO: signal count 17
  23. RW-shared spins 0, rounds 0, OS waits 0
  24. RW-excl spins 125, rounds 242, OS waits 1
  25. RW-sx spins 0, rounds 0, OS waits 0
  26. Spin rounds per wait: 0.00 RW-shared, 1.94 RW-excl, 0.00 RW-sx
  27. ------------
  28. TRANSACTIONS
  29. ------------
  30. Trx id counter 16853
  31. Purge done for trx's n:o < 16853 undo n:o < 0 state: running but idle
  32. History list length 90
  33. LIST OF TRANSACTIONS FOR EACH SESSION:
  34. ---TRANSACTION 283929911699248, not started
  35. 0 lock struct(s), heap size 1136, 0 row lock(s)
  36. ---TRANSACTION 283929911700120, not started
  37. 0 lock struct(s), heap size 1136, 0 row lock(s)
  38. --------
  39. FILE I/O
  40. --------
  41. I/O thread 0 state: wait Windows aio (insert buffer thread)
  42. I/O thread 1 state: wait Windows aio (log thread)
  43. I/O thread 2 state: wait Windows aio (read thread)
  44. I/O thread 3 state: wait Windows aio (read thread)
  45. I/O thread 4 state: wait Windows aio (read thread)
  46. I/O thread 5 state: wait Windows aio (read thread)
  47. I/O thread 6 state: wait Windows aio (write thread)
  48. I/O thread 7 state: wait Windows aio (write thread)
  49. I/O thread 8 state: wait Windows aio (write thread)
  50. I/O thread 9 state: wait Windows aio (write thread)
  51. Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
  52. ibuf aio reads:, log i/o's:, sync i/o's:
  53. Pending flushes (fsync) log: 0; buffer pool: 0
  54. 1122 OS file reads, 1335 OS file writes, 420 OS fsyncs
  55. 0.00 reads/s, 0 avg bytes/read, 0.35 writes/s, 0.21 fsyncs/s
  56. -------------------------------------
  57. INSERT BUFFER AND ADAPTIVE HASH INDEX
  58. -------------------------------------
  59. Ibuf: size 1, free list len 0, seg size 2, 0 merges
  60. merged operations:
  61. insert 0, delete mark 0, delete 0
  62. discarded operations:
  63. insert 0, delete mark 0, delete 0
  64. Hash table size 34679, node heap has 1 buffer(s)
  65. Hash table size 34679, node heap has 2 buffer(s)
  66. Hash table size 34679, node heap has 0 buffer(s)
  67. Hash table size 34679, node heap has 0 buffer(s)
  68. Hash table size 34679, node heap has 1 buffer(s)
  69. Hash table size 34679, node heap has 1 buffer(s)
  70. Hash table size 34679, node heap has 2 buffer(s)
  71. Hash table size 34679, node heap has 7 buffer(s)
  72. 0.00 hash searches/s, 0.21 non-hash searches/s
  73. ---
  74. LOG
  75. ---
  76. Log sequence number 34460271
  77. Log buffer assigned up to 34460271
  78. Log buffer completed up to 34460271
  79. Log written up to 34460271
  80. Log flushed up to 34460271
  81. Added dirty pages up to 34460271
  82. Pages flushed up to 34460271
  83. Last checkpoint at 34460271
  84. 402 log i/o's done, 0.15 log i/o's/second
  85. ----------------------
  86. BUFFER POOL AND MEMORY
  87. ----------------------
  88. Total large memory allocated 137363456
  89. Dictionary memory allocated 473442
  90. Buffer pool size 8192
  91. Free buffers 6911
  92. Database pages 1267
  93. Old database pages 487
  94. Modified db pages 0
  95. Pending reads 0
  96. Pending writes: LRU 0, flush list 0, single page 0
  97. Pages made young 1, not young 0
  98. 0.00 youngs/s, 0.00 non-youngs/s
  99. Pages read 1097, created 170, written 810
  100. 0.00 reads/s, 0.00 creates/s, 0.15 writes/s
  101. Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
  102. Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
  103. LRU len: 1267, unzip_LRU len: 0
  104. I/O sum[0]:cur[0], unzip sum[0]:cur[0]
  105. --------------
  106. ROW OPERATIONS
  107. --------------
  108. 0 queries inside InnoDB, 0 queries in queue
  109. 0 read views open inside InnoDB
  110. Process ID=472, Main thread ID=00000000000039CC , state=sleeping
  111. Number of rows inserted 250, updated 462, deleted 194, read 53829
  112. 0.00 inserts/s, 0.03 updates/s, 0.00 deletes/s, 0.03 reads/s
  113. ----------------------------
  114. END OF INNODB MONITOR OUTPUT
  115. ============================
  116. 1 row in set (0.00 sec)
  117. *************************** 1. row ***************************
  118. File: binlog.000021
  119. Position: 4419
  120. Binlog_Do_DB:
  121. Binlog_Ignore_DB:
  122. Executed_Gtid_Set:
  123. 1 row in set (0.00 sec)

image.png

session3:update

  1. mysql> update user set user_id = 111 where id = 1;
  2. Query OK, 0 rows affected (0.00 sec)
  3. Rows matched: 1 Changed: 0 Warnings: 0
  4. mysql> show engine innodb status\Gshow master status\G
  5. *************************** 1. row ***************************
  6. Type: InnoDB
  7. Name:
  8. Status:
  9. =====================================
  10. 2020-07-24 15:12:17 0x3b50 INNODB MONITOR OUTPUT
  11. =====================================
  12. Per second averages calculated from the last 13 seconds
  13. -----------------
  14. BACKGROUND THREAD
  15. -----------------
  16. srv_master_thread loops: 25 srv_active, 0 srv_shutdown, 26592 srv_idle
  17. srv_master_thread log flush and writes: 0
  18. ----------
  19. SEMAPHORES
  20. ----------
  21. OS WAIT ARRAY INFO: reservation count 19
  22. OS WAIT ARRAY INFO: signal count 18
  23. RW-shared spins 0, rounds 0, OS waits 0
  24. RW-excl spins 125, rounds 242, OS waits 1
  25. RW-sx spins 0, rounds 0, OS waits 0
  26. Spin rounds per wait: 0.00 RW-shared, 1.94 RW-excl, 0.00 RW-sx
  27. ------------
  28. TRANSACTIONS
  29. ------------
  30. Trx id counter 16855
  31. Purge done for trx's n:o < 16855 undo n:o < 0 state: running but idle
  32. History list length 91
  33. LIST OF TRANSACTIONS FOR EACH SESSION:
  34. ---TRANSACTION 283929911699248, not started
  35. 0 lock struct(s), heap size 1136, 0 row lock(s)
  36. ---TRANSACTION 283929911700120, not started
  37. 0 lock struct(s), heap size 1136, 0 row lock(s)
  38. --------
  39. FILE I/O
  40. --------
  41. I/O thread 0 state: wait Windows aio (insert buffer thread)
  42. I/O thread 1 state: wait Windows aio (log thread)
  43. I/O thread 2 state: wait Windows aio (read thread)
  44. I/O thread 3 state: wait Windows aio (read thread)
  45. I/O thread 4 state: wait Windows aio (read thread)
  46. I/O thread 5 state: wait Windows aio (read thread)
  47. I/O thread 6 state: wait Windows aio (write thread)
  48. I/O thread 7 state: wait Windows aio (write thread)
  49. I/O thread 8 state: wait Windows aio (write thread)
  50. I/O thread 9 state: wait Windows aio (write thread)
  51. Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
  52. ibuf aio reads:, log i/o's:, sync i/o's:
  53. Pending flushes (fsync) log: 0; buffer pool: 0
  54. 1122 OS file reads, 1344 OS file writes, 426 OS fsyncs
  55. 0.00 reads/s, 0 avg bytes/read, 0.69 writes/s, 0.46 fsyncs/s
  56. -------------------------------------
  57. INSERT BUFFER AND ADAPTIVE HASH INDEX
  58. -------------------------------------
  59. Ibuf: size 1, free list len 0, seg size 2, 0 merges
  60. merged operations:
  61. insert 0, delete mark 0, delete 0
  62. discarded operations:
  63. insert 0, delete mark 0, delete 0
  64. Hash table size 34679, node heap has 1 buffer(s)
  65. Hash table size 34679, node heap has 2 buffer(s)
  66. Hash table size 34679, node heap has 0 buffer(s)
  67. Hash table size 34679, node heap has 0 buffer(s)
  68. Hash table size 34679, node heap has 1 buffer(s)
  69. Hash table size 34679, node heap has 1 buffer(s)
  70. Hash table size 34679, node heap has 2 buffer(s)
  71. Hash table size 34679, node heap has 7 buffer(s)
  72. 0.00 hash searches/s, 0.08 non-hash searches/s
  73. ---
  74. LOG
  75. ---
  76. Log sequence number 34460759
  77. Log buffer assigned up to 34460759
  78. Log buffer completed up to 34460759
  79. Log written up to 34460759
  80. Log flushed up to 34460759
  81. Added dirty pages up to 34460759
  82. Pages flushed up to 34460759
  83. Last checkpoint at 34460759
  84. 405 log i/o's done, 0.23 log i/o's/second
  85. ----------------------
  86. BUFFER POOL AND MEMORY
  87. ----------------------
  88. Total large memory allocated 137363456
  89. Dictionary memory allocated 473442
  90. Buffer pool size 8192
  91. Free buffers 6911
  92. Database pages 1267
  93. Old database pages 487
  94. Modified db pages 0
  95. Pending reads 0
  96. Pending writes: LRU 0, flush list 0, single page 0
  97. Pages made young 1, not young 0
  98. 0.00 youngs/s, 0.00 non-youngs/s
  99. Pages read 1097, created 170, written 814
  100. 0.00 reads/s, 0.00 creates/s, 0.31 writes/s
  101. Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
  102. Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
  103. LRU len: 1267, unzip_LRU len: 0
  104. I/O sum[0]:cur[0], unzip sum[0]:cur[0]
  105. --------------
  106. ROW OPERATIONS
  107. --------------
  108. 0 queries inside InnoDB, 0 queries in queue
  109. 0 read views open inside InnoDB
  110. Process ID=472, Main thread ID=00000000000039CC , state=sleeping
  111. Number of rows inserted 250, updated 463, deleted 194, read 53830
  112. 0.00 inserts/s, 0.08 updates/s, 0.00 deletes/s, 0.08 reads/s
  113. ----------------------------
  114. END OF INNODB MONITOR OUTPUT
  115. ============================
  116. 1 row in set (0.00 sec)
  117. *************************** 1. row ***************************
  118. File: binlog.000021
  119. Position: 4748
  120. Binlog_Do_DB:
  121. Binlog_Ignore_DB:
  122. Executed_Gtid_Set:
  123. 1 row in set (0.00 sec)
  124. mysql> select * from user where id = 1;
  125. +----+---------+-----+------+---------------------+-----------+
  126. | id | user_id | age | name | login_time | address |
  127. +----+---------+-----+------+---------------------+-----------+
  128. | 1 | 111 | 18 | Fc | 2020-07-23 22:16:57 | 北京市 |
  129. +----+---------+-----+------+---------------------+-----------+
  130. 1 row in set (0.00 sec)

image.png
对比session2中的upadted发现执行改变

C.总结

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