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 ...
随机推荐
- android 自定义progressDialog实现
我们在项目中经常会遇到这样一个应用场景:执行某个耗时操作时,为了安抚用户等待的烦躁心情我们一般会使用进度条之类的空间,在android中让 大家最容易想到的就是progressbar或者progres ...
- “too many open files" ----增大打开的文件数
http://www.cnblogs.com/ibook360/archive/2012/05/11/2495405.html [root@localhost ~]# ab -n -c http:/ ...
- 获取context path或者basePath
转自:http://hexudonghot.blog.163.com/blog/static/532043422012112264411234/ 在jsp中获取context path或者basePa ...
- JDK5-注解
注解是一个类,一个声明就是一个对象 1. 简单注解 @SuppressWarnings("msg") - 压缩/抑制警告 @Deprecated - 声明过时 @Override ...
- Sublime Text 2 自动开启换行 Word Wrap
首先当然要夸一下神器 Sublime Text 2,自从第一次用我就彻底把神马 Notepad++ 和 TextMate 打入冷宫,用来开发 WEB 项目从此 IDE 都不需要了! 下面讲讲如何自动开 ...
- jvm-初探
目录 1,Java体系结构 2.jvm执行引擎 3,ClassLoader的体系结构 4,java class文件 概述 其实,学java不算新手了,但是却感觉很多基本的知识,我们一开始也许是记住而不 ...
- Linux和windows下清除svn保存的账号密码信息
linux是什么用户登录就是什么用户的home下,如root用户就是/root,如果xiangdong就是/home/xiangdong 用Svn时会有一种需求是需要换个帐号测试一下什么的,但往往有缓 ...
- Action class [userAction] not found
今天在做SSI框架整合的时候报了一个这样的错误:Action class [userAction] not found - action - file:F:\workspace\.metadata\. ...
- ubuntu下apache与php配置
实验环境 uname -a Linux tomato 4.4.0-34-generic #53-Ubuntu SMP Wed Jul 27 16:06:39 UTC 2016 x86_64 x86_6 ...
- hdu 2460 poj 3694 (双联通+LCA)
在给出的两个点上加一条边,求剩下桥的数量,,不会LCA在线,就用了最普通的,先Tarjan双联通缩点,然后将缩完的图建成一棵树,树的所有边就是桥了,如果在任意两点间加一条边的话,那么从两点到最近公共祖 ...