相對其他數據庫而言,MySQL的鎖機制比較簡單,其最顯著的特點是不同的存儲引擎支持不同的鎖機制,但總的來説,mysql各種存儲引擎使用了三種類型的鎖定機制:行級鎖定、頁級鎖定和表級鎖定。其中,MyISAM主要使用表級鎖定,而使用行級鎖定的主要是Innodb。 <style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style> <style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style> <style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style>
<style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style>
①表級鎖:開銷小,加鎖快;不會出現死鎖;鎖定粒度大,發生鎖衝突的概率最高,并發度最低。
<style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style> ②行級鎖:開銷大,加鎖慢;會出現死鎖;鎖定粒度最小,發生鎖衝突的概率最低,并發度也最高。
<style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style> ③頁級鎖:開銷和加鎖時間界于表鎖和行鎖之間;會出現死鎖;鎖定粒度界于表鎖和行鎖之間,并發度一般
<style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style> 每种锁都是按各自的应用场景而优化设计的。表锁可能适合web应用;而行级锁可能更适合OLTP系统。<style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style>
<style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style>
<style type="text/css">pre { font-family: "Ubuntu"; }p { margin-bottom: 0.21cm; }</style>
本文介绍了MySQL中不同存储引擎支持的不同类型的锁定机制,包括行级锁、页级锁和表级锁的特点及应用场景,帮助理解MySQL并发控制的核心概念。
7360

被折叠的 条评论
为什么被折叠?



