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. 自动开机和自动关机设定方法(包括linux和windows)

    (一) linux 机器 1.关机 : 编辑 /etc/crontab添加一条并且保证crontab服务的运行即可 f1 f2 f3 f4 f5 root sudo shutdown –h now 假 ...

  2. zoj 2112 Dynamic Rankings(主席树&动态第k大)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  3. 通过扩展RandomAccessFile类使之具备Buffer改善I/O性能--转载

    主体: 目前最流行的J2SDK版本是1.3系列.使用该版本的开发人员需文件随机存取,就得使用RandomAccessFile类.其I/O性能较之其它常用开发语言的同类性能差距甚远,严重影响程序的运行效 ...

  4. JBoss EAP6/AS7/WildFly: How to Use Properties Files Outside Your Archive--reference

    Introduction I’d like to preface this post with, really, all properties files should be inside your ...

  5. Android更新UI的几种方式

    之前做过一个Android采集心电图数据的程序,那才是真正的多线程,之前写的小程序:比如下载个文件,从socket接受大一点的数据流然后在ui上更新进度,我都感觉这就叫做多线程了,其实这啥都不算,用个 ...

  6. android strings.xml转义字符, 注意细节解决(转)

    XML转义字符 以下为XML标志符的数字和字符串转义符 "     (" 或 ") '     (' 或 ') &     (& 或 & ...

  7. .NET 拼音检索

    微软提供了一个Visual Studio International Pack 组件,可以转换简繁体,或者将汉字转换为拼音以及其他语言的支持. https://www.microsoft.com/zh ...

  8. display:box和flex的区别

    没区别,仅是各阶段草案命名flex是最新的 但是在实际的浏览器测试中,display: flex 不能完全替代display: -webkit-box display: box 使用可以参考http: ...

  9. jquery获取value值

    $(function(){ alert(1); var a=$("#a004").val(); var a1=$("#b004").val(); //.val就 ...

  10. LINUX 内核代码 errno 错误代码提示 /include/asm/errno.h

    首先在自己的程序中#include<errno.h> 添加打印errno的语句 printf("errno is: %d\n",errno); 根据errno的值查错. ...