If one session has a shared or exclusive lock on record R in an index, another session cannot insert a new index 

record in the gap immediately before R in the index order. 

如果一个session 有一个共享或者排它锁在记录R上,另外的session 不能插入新的index record 在before R这个区间

Session 1:

mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from SmsTest where phoneNo=10 for update;
+-------+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+-------+---------+-------------+--------+
| 10 | 10 | 2 | 1 |
| 45239 | 10 | 1 | 1 |
| 45252 | 10 | 1 | 1 |
+-------+---------+-------------+--------+
3 rows in set (0.01 sec) Session 2: Database changed
mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(1,1,1);
Query OK, 1 row affected (0.01 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(2,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(3,1,1);
Query OK, 1 row affected (0.01 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(4,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(5,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(6,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(7,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(8,1,1);
Query OK, 1 row affected (0.01 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(9,1,1);
^[[A
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(9,1,1);
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(10,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(11,1,1);
Query OK, 1 row affected (0.01 sec)

If one session has a shared or exclusive lock on record R in an index, another session cannot insert的更多相关文章

  1. Shared and Exclusive Locks 共享和排它锁

    14.5 InnoDB Locking and Transaction Model InnoDB 锁和事务模型 14.5.1 InnoDB Locking 14.5.2 InnoDB Transact ...

  2. MySQL Shared and Exclusive Locks

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

  3. 启动weblogic的错误:Could not obtain an exclusive lock to the embedded LDAP data files directory

    http://hi.baidu.com/kaisep/item/0e4bf6ee5da001d1ea34c986 源地址 启动weblogic的错误:Could not obtain an exclu ...

  4. java:Session(概述,三层架构实例(实现接口封装JDBC),Session实现简单购物车实例)

    1.Session概述: Session:在计算机中,尤其是在网络应用中,称为“会话控制”.Session 对象存储特定用户会话所需的属性及配置信息.这样,当用户在应用程序的 Web 页之间跳转时,存 ...

  5. 深入理解Java并发框架AQS系列(三):独占锁(Exclusive Lock)

    一.前言 优秀的源码就在那里 经过了前面两章的铺垫,终于要切入正题了,本章也是整个AQS的核心之一 从本章开始,我们要精读AQS源码,在欣赏它的同时也要学会质疑它.当然本文不会带着大家逐行过源码(会有 ...

  6. Mysql讲解数据库并发控制知识

    1.下载Mysql并安装,我喜欢不用安装的zip版,cd到bin目录下,先修改下mysql的密码. mysqladmin -u root -p password mysql ,第一次运行并修改mysq ...

  7. 使用next-key locks 用于搜索和索引扫描,可以防止幻读

    Next-Key Locks A next-key lock is a combination of a record lock on the index record and a gap lock ...

  8. MySQL 基础知识梳理学习(六)----锁

    1.什么是锁: 对共享资源进行并发访问控制,提供数据的完整性和一致性. 2.锁的区别: 类型 lock latch 对象 事务 线程 保护 数据库内容 内存数据结构 持续时间 整个事务过程 临界资源 ...

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

随机推荐

  1. android 30 下拉列表框:ArrayAdapter和Spinner.

    package com.sxt.day05_04; import android.os.Bundle; import android.app.Activity; import android.cont ...

  2. GDB踪函数的完整调用过程 及原理

    http://www.lenky.info/archives/2013/02/2202 Breakpoint , .so. (gdb) bt # .so. # .so. # .so. # .so. # ...

  3. Map的迭代操作

    Map的迭代操作 public static void main(String[] args) { Map<String, List<Integer>> map = new H ...

  4. sql知识点的积累和使用过的例子

    越来越发现自己的sql方面的知识的欠缺,所以只能放低姿态一点一点的学了 一 游标和charIndex的使用. 游标我一直没用过,以前只是在同事们写的存储过程里见过,但是一直没看明白(可是我就是比较笨吧 ...

  5. Android开发常见错误类型一览表

    这是我的第一个博客,我会一直添加我在Android开发中遇到的错误,用来记录我开发中踩过的那些坑 ------------------------分割线------------------------ ...

  6. Android开发 --微信支付开发(转载!)(开发工具:Eclipse)

    Android_APP 微信支付接口开发 日期:2015-10-06 12:47:33 作者: 来源: 人气:3549 1.首先说一下我们在开发微信支付接口的时候遇到最多和最疑惑的问题,那就是明明 a ...

  7. php_curl扩展在WINDOWS2003上如何添加

    一.使用星外PHP安装后 二.修改环境变量,PATH: c:\php;c:\php\ext;%SystemRoot%\system32;

  8. C# XML文件操作类XmlHelper

    类的完整代码: using System;using System.Collections;using System.Xml; namespace Keleyi.Com.XmlDAL{public c ...

  9. c++primerplus(第六版)编程题——第5章(循环和关系表达式)

    声明:作者为了调试方便,每一章的程序写在一个工程文件中,每一道编程练习题新建一个独立文件,在主函数中调用,我建议同我一样的初学者可以采用这种方式,调试起来会比较方便. (具体方式参见第3章模板) 1. ...

  10. SGU 144.Meeting

    题目: 两支地区ACM比赛的队伍决定为了国际决赛而在一起集训. 他们约定在某天的 X 时到 Y 时的某一时刻相会. 但由于他们很少按时到 (有的队伍比赛那天都会迟到), 他们没有设定一个确切的相遇时间 ...