Shared and Exclusive Locks 共享和排它锁
14.5 InnoDB Locking and Transaction Model InnoDB 锁和事务模型 14.5.1 InnoDB Locking
14.5.2 InnoDB Transaction Model
14.5.3 Locks Set by Different SQL Statements in InnoDB
14.5.4 Phantom Rows
14.5.5 Deadlocks in InnoDB 实现一个大规模的,繁忙的,或者可扩展的数据库应用,从不同数据库系统的大量代码,或者调整MySQL 性能, 它是重要的了解InnoDB 锁和InnoDB 事务模型 本节讨论几个议题关于InnoDB 锁和InnoDB 事务模型: 14.5.1 InnoDB Locking 这个章节描述InnoDB使用的锁的类型: Shared and Exclusive Locks Intention Locks Record Locks Gap Locks Next-Key Locks Insert Intention Locks AUTO-INC Locks Shared and Exclusive Locks 共享和排它锁 InnoDB 实现标准的航机所 有两种类型的锁,shared (S) locks and exclusive (X) locks. 共享和排它锁 1.一个共享锁允许事务是有一个锁来读取一行 2.一个排它锁允许事务持有锁来更新或者删除记录 如果事务T1 持有一个共享锁在记录r, 另外一个事务T2 请求一个lock 在记录r 是如下处理: 1.T2请求S锁可以立即被授予,作为结果,T1和T2 都持有S锁在记录r上 2. T2请求X锁不能马上授权 如果一个事务是有一个排它锁在记录r上,从其他事务T2请求任何类型的锁都不能被立即授予。 相反, 事务T2 只能等待事务T1释放它在记录r上的锁 ·共享锁(S):SELECT * FROM table_name WHERE ... LOCK IN SHARE MODE。 ·排他锁(X):SELECT * FROM table_name WHERE ... FOR UPDATE。 模式: 第一种情况 session1 持有共享锁: Session 1加共享锁: mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from aa where username='admin' LOCK IN SHARE MODE;
+----------+----------------------------------+-----------+
| username | password | authority |
+----------+----------------------------------+-----------+
| admin | 0192023a7bbd73250516f069df18b500 | 1 |
+----------+----------------------------------+-----------+
1 row in set (0.00 sec) Session 2此时也可以加共享锁: mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from aa where username='admin' LOCK IN SHARE MODE;
+----------+----------------------------------+-----------+
| username | password | authority |
+----------+----------------------------------+-----------+
| admin | 0192023a7bbd73250516f069df18b500 | 1 |
+----------+----------------------------------+-----------+
1 row in set (0.00 sec) mysql> select * from aa where username='admin' for update; 加排它锁会HANG 第一种情况 session2 持有排它锁: Session 1持有排它锁: mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from aa where username='admin' for update;
+----------+----------------------------------+-----------+
| username | password | authority |
+----------+----------------------------------+-----------+
| admin | 0192023a7bbd73250516f069df18b500 | 1 |
+----------+----------------------------------+-----------+
1 row in set (0.00 sec) Session 2: mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from aa where username='admin' LOCK IN SHARE MODE; 无法获取共享锁 也无法获取排它锁
Shared and Exclusive Locks 共享和排它锁的更多相关文章
- MySQL Shared and Exclusive Locks
官方文档 InnoDB implements standard row-level locking where there are two types of locks, shared (S) loc ...
- If one session has a shared or exclusive lock on record R in an index, another session cannot insert
If one session has a shared or exclusive lock on record R in an index, another session cannot insert ...
- vmware shared holder 虚拟机设置共享目录
1, 安装 vm-tools http://askubuntu.com/questions/29284/how-do-i-mount-shared-folders-win7-host-in-ubunt ...
- Innodb中的锁
Innodb中的锁 共享锁和排它锁(Shared and Exclusive Locks)共享锁和排它锁是行级锁,有两种类型的行级锁 共享锁(s lock)允许持有锁的事务对行进行读取操作 排它锁(x ...
- 14.3.3 Locks Set by Different SQL Statements in InnoDB 不同的SQL语句在InnoDB里的锁设置
14.3.3 Locks Set by Different SQL Statements in InnoDB 不同的SQL语句在InnoDB里的锁设置 locking read, 一个UPDATE,或 ...
- InnoDB Record, Gap, and Next-Key Locks
InnoDB has several types of record-level locks including record locks, gap locks, and next-key locks ...
- 转 MYSQL InnoDB Record, Gap, and Next-Key Locks
http://dev.mysql.com/doc/refman/5.0/en/innodb-record-level-locks.html InnoDB has several types of re ...
- Locks Set by Different SQL Statements in InnoDB
A locking read, an UPDATE, or a DELETE generally set record locks on every index record that is scan ...
- 小白学习mysql 之 innodb locks
Innodb 锁类型: Shared and Exclusive Locks Intention Locks Record Locks Gap Locks Next-Key Locks Insert ...
随机推荐
- Struts2方法调用的三种方式
在Struts2中方法调用概括起来主要有三种形式 第一种方式:指定method属性 <action name="student" class="com.itmyho ...
- poj2586 Y2K Accounting Bug(贪心)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...
- android 怎样内置/预置/预编译文件(运行程序,应用程序,apk, jar, lib 等随意文件)到系统中
方法一: 如果要内置的软件名称为iperf.exe 1. 将iperf.exe放到Codebase的随意一个文件夹下(该文件夹必须可以在搜索Android.mk时被搜索到),比方system/ipe ...
- STL——increment/decrement/dereference操作符
increment/dereference操作符在迭代器的实现上占有非常重要的地位,因为任何一个迭代器都必须实现出前进(increment,operator++)和取值(dereference,ope ...
- Change value of string array at debug eclipse--转
Question: I have an application, but to test something, I need to change value of a String[]. But wh ...
- IOS 获取通讯录中信息
获取通讯录中信息 一. 我们设置一个ABAddressBookRef类型的属性addressBook. 二. 要获得通讯录中的信息,我们需要获取访问通讯录的权限. 在运行下面的获取权限的方法的时候,系 ...
- iOS开发系列之运动事件
前面我们主要介绍了触摸事件以及由触摸事件引出的手势识别,下面我们简单介绍一下运动事件.在iOS中和运动相关的有三个事件:开始运动.结束运动.取消运动. 监听运动事件对于UI控件有个前提就是监听对象必须 ...
- 【IOS】关于CGTransform的几个动画
1.CGTransform主要三大功能,平移(Translation).缩放(Scale).旋转(Rotate). 平移: self.imageView.transform = CGAffineTra ...
- linux 调试
strace gdb tcpdump valgrind perf
- Android带参数链接请求服务器
public void taste() { //设默认值 SharedPreferences.Editor editor = this.getSharedPreferences("setti ...