mysql读操作分为2种类型:snapshot read及current read,前者基于mysql mvcc实现,读取数据块是undo block,后者是基于当前数据块。这2种不同的读取类型与锁的关系是什么,本文作一点儿简要的记录。
微信公众号
微信
snapshot read由于操作非当前数据块,不会加锁
x --排它锁
s --共享锁
查询current read不同操作场景持锁语句
(注:关注列lock_mode)
mysql> select * from information_schema.innodb_locks; +-------------------------+-----------------+-----------+-----------+------------------+-----------------+------------+-----------+----------+----------------+ | lock_id | lock_trx_id | lock_mode | lock_type | lock_table | lock_index | lock_space | lock_page | lock_rec | lock_data | +-------------------------+-----------------+-----------+-----------+------------------+-----------------+------------+-----------+----------+----------------+ | 11909:473:3:2 | 11909 | X | RECORD | `zxydb`.`t_read` | GEN_CLUST_INDEX | 473 | 3 | 2 | 0x00000836F561 | | 421207096970864:473:3:2 | 421207096970864 | S | RECORD | `zxydb`.`t_read` | GEN_CLUST_INDEX | 473 | 3 | 2 | 0x00000836F561 | +-------------------------+-----------------+-----------+-----------+------------------+-----------------+------------+-----------+----------+----------------+ 2 rows in set, 1 warning (0.00 sec)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。