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 共享和排它锁的更多相关文章

  1. MySQL Shared and Exclusive Locks

    官方文档 InnoDB implements standard row-level locking where there are two types of locks, shared (S) loc ...

  2. 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 ...

  3. vmware shared holder 虚拟机设置共享目录

    1, 安装 vm-tools http://askubuntu.com/questions/29284/how-do-i-mount-shared-folders-win7-host-in-ubunt ...

  4. Innodb中的锁

    Innodb中的锁 共享锁和排它锁(Shared and Exclusive Locks)共享锁和排它锁是行级锁,有两种类型的行级锁 共享锁(s lock)允许持有锁的事务对行进行读取操作 排它锁(x ...

  5. 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,或 ...

  6. InnoDB Record, Gap, and Next-Key Locks

    InnoDB has several types of record-level locks including record locks, gap locks, and next-key locks ...

  7. 转 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 ...

  8. 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 ...

  9. 小白学习mysql 之 innodb locks

    Innodb 锁类型: Shared and Exclusive Locks Intention Locks Record Locks Gap Locks Next-Key Locks Insert ...

随机推荐

  1. [PWA] 4. Hijacking Request

    We want to do offline first, the first thing we need to do is we should able to catch the browser re ...

  2. [Flux] Stores

    Store, in Flux which manager the state of the application. You can use EventEmiiter to listen to the ...

  3. MVC模式下的数据展示:EasyUI的datagrid

    我的数据库设计是一张老师表teacher,一张学生表student,一个教师对应多个学生,在学生一方建立外键; 还有一点想清楚,需要展示的数据是根据什么来的,是成功登陆的用户的id?还是直接展示所有的 ...

  4. C#中的转义字符

    一些常用的转义字符: \n  换行 \b  backspace,删除光标前面的一个字符 \t  tab键 由多个空格组成的一个字符,具有行与行之间的对齐功能 \\  \ 如果在字符串前面加@的话: 1 ...

  5. 正则表达式中/i,/g,/m的作用

    一./i (ignorCase)忽略大小写,注意仅是忽略大小写,并不忽略全半角. 二./g (globle)全文查找出现的所有匹配字符 三./m 1.(mutiple)多行查找2.m 影响 ^.$.3 ...

  6. java.lang.UnsupportedClassVersionError: Bad version number in .class file

    java.lang.UnsupportedClassVersionError: Bad version number in .class file造成这种过错是ni的支撑Tomcat运行的JDK版本与 ...

  7. 7——使用TextView实现跑马灯

    首先给TextView添加一个单行限制: android:singleLine="true" - 解决方案一 更改TextView的一个属性: android:ellipsize= ...

  8. cocos2dx 3.2中的物理引擎初探(一)

    cocos2dx在设计之初就集成了两套物理引擎,它们是box2d和chipmunk.我目前使用的是最新版的cocos2dx 3.2.引擎中默认使用的是chipmunk,如果想要改使用box2d的话,需 ...

  9. 错误:Duplicate interface definition for class

    错误: Duplicate interface definition for class  "类名称" 原因:在工程中有相同的文件或相同的 @interface 类名称 解决办法: ...

  10. Java学习----你的选择是什么-条件结构

    import java.util.Scanner; public class Student { public static void main(String[] args) { byte money ...