ansn001 发表于 2013-1-29 16:29:16

mysql锁机制

转自:http://thebye85.iteye.com/blog/1463546,仅借学习
MySQL有三种锁的级别:页级、表级、行级。
MyISAM和MEMORY存储引擎采用的是表级锁(table-level locking);BDB存储引擎采用的是页面锁(page-levellocking),但也支持表级锁;InnoDB存储引擎既支持行级锁(row-level locking),也支持表级锁,但默认情况下是采用行级锁。以下讲的都是在innodb引擎的前提下。
 
1、共享锁(Share Locks,即S锁),使用方式select ... LOCK IN SHARE MODESELECT ... LOCK IN SHARE MODE sets a shared mode lock on the rows read. A shared mode lock enables other sessions to read the rows but not to modify them. The rows read are the latest available, so if they belong to another transaction that has not yet committed, the read blocks until that transaction ends.
如:事务A中有select ... lock in share mode未提交前,其它事务的可以读本次事务前的最新值,写操作会阻塞直到事务A提交后才执行。
 
例子:
<div class="dp-highlighter" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; margin-left: 9px; line-height: 25px; text-align: left; padding: 1px;"><div class="bar"><div class="tools" style="font-weight: bold; padding: 3px; margin: 0px;">Sql代码  http://thebye85.iteye.com/images/icon_star.png
页: [1]
查看完整版本: mysql锁机制