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 ...
随机推荐
- poj--1579--(DFS+记忆化搜索之经典)
记忆化搜索 记忆化搜索:算法上依然是搜索的流程,但是搜索到的一些解用 动态规划的那种思想和模式作一些保存. 一般说来,动态规划总要遍历所有的状态,而搜索可以排除一些无效状态. 更重要的是搜索还可以 ...
- [PWA] 2. Service worker life cycle
Once serive worker is registered, the first time we go to the app, we cannot see the logs from servc ...
- Android学习小Demo一个显示行线的自定义EditText
今天在处理一个EditText的时候,想着把EditText做成像一本作业本上的纸一样,每一行都可以由线条隔开,具体效果如下: 1)最开始的思路 一开始的想法是很简单的,找出每一行的高度,然后一行一行 ...
- Android 连接 SQL Server (jtds方式)——上
本文将介绍开发Android程序,连接SQL Server,通过第三方包jtds的方式. 如果你有同样的需求,请跟着做一遍,博主将以最详细的方式,进行介绍. 首先说明,Java.Android连接SQ ...
- jQuery创建ajax关键词数据搜索
在web开发过程当中,我们经常需要在前台页面输入关键词进行数据的搜索,我们通常使用的搜索方式是将搜索结果用另一个页面显示,这样的方式对于搭建高性能网站来说不是最合适的,今天给大家分享一下如何使用 jQ ...
- 七.生成n位随机字符串
--1.借助newid() go --创建视图(因为在函数中无法直接使用newid()) create view vnewid as select newid() N'MacoId'; go --创建 ...
- Asp.net 事务处理
事务处理是在数据处理时经常遇到的问题,经常用到的方法有以下三种总结整理如下:方法1:直接写入到sql 中在存储过程中使用 BEGIN TRANS, COMMIT TRANS, ROLLBACK TRA ...
- 一些iOS笔试题目
1.什么是arc?(arc是为了解决什么问题诞生的?) 首先解释ARC: automatic reference counting自动引用计数. ARC几个要点: 在对象被创建时 retain cou ...
- 基于ThinkPHP+AJAX的省市区三级联动
练习,就当练习. 省市区三级联动,样式如下图所示: 1,导入两个js文件并且导入数据库文件. 两个js文件分别是jquery-2.1.4.min.js和jquery-1.js,数据库文件,见附件. 2 ...
- iPhone 6 图像渲染揭秘(转)
几天前,Apple发布了iPhone 6 Plus. 新的iPhone大幅改变了图像在屏幕上渲染的方式.我们做了一个图表进行详细分析. 分析. 转自:转送