Session 1:
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from SmsTest where phoneNo between 30 and 40 for update;
+----+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+----+---------+-------------+--------+
| 30 | 30 | 2 | 1 |
| 31 | 31 | 2 | 1 |
| 32 | 32 | 2 | 1 |
| 33 | 33 | 2 | 1 |
| 34 | 34 | 2 | 1 |
| 35 | 35 | 2 | 1 |
| 36 | 36 | 2 | 1 |
| 37 | 37 | 2 | 1 |
| 38 | 38 | 2 | 1 |
| 39 | 39 | 2 | 1 |
| 40 | 40 | 2 | 1 |
+----+---------+-------------+--------+
11 rows in set (0.00 sec) mysql> explain select * from SmsTest where phoneNo between 30 and 40 for update;
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
| 1 | SIMPLE | SmsTest | range | SmsTest_idx1 | SmsTest_idx1 | 4 | NULL | 11 | Using index condition |
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
1 row in set (0.00 sec) Session 2: mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(28,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(29,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(30,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(31,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(32,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(33,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(34,1,1);--hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(40,1,1); --hang mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(41,1,1);
Query OK, 1 row affected (0.01 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(42,1,1);
Query OK, 1 row affected (0.04 sec) 在30-40这个区间无法插入,RR需要区间锁来防止幻读 修改事务隔离为transaction-isolation =READ-COMMITTED mysql> select @@tx_isolation;
+----------------+
| @@tx_isolation |
+----------------+
| READ-COMMITTED |
+----------------+
1 row in set (0.00 sec) mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> select * from SmsTest where phoneNo between 30 and 40 for update;
+----+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+----+---------+-------------+--------+
| 30 | 30 | 2 | 1 |
| 31 | 31 | 2 | 1 |
| 32 | 32 | 2 | 1 |
| 33 | 33 | 2 | 1 |
| 34 | 34 | 2 | 1 |
| 35 | 35 | 2 | 1 |
| 36 | 36 | 2 | 1 |
| 37 | 37 | 2 | 1 |
| 38 | 38 | 2 | 1 |
| 39 | 39 | 2 | 1 |
| 40 | 40 | 2 | 1 |
+----+---------+-------------+--------+
11 rows in set (0.01 sec) mysql> explain select * from SmsTest where phoneNo between 30 and 40 for update;
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
| 1 | SIMPLE | SmsTest | range | SmsTest_idx1 | SmsTest_idx1 | 4 | NULL | 11 | Using index condition |
+----+-------------+---------+-------+---------------+--------------+---------+------+------+-----------------------+
1 row in set (0.01 sec) Session2: Database changed
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(28,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(29,1,1);
Query OK, 1 row affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(30,1,1);
Query OK, 1 row affected (0.00 sec) mysql> commit;
Query OK, 0 rows affected (0.00 sec) mysql> insert into zjzc.SmsTest(PhoneNo,channelType,status) values(31,1,1);
Query OK, 1 row affected (0.00 sec) Session 1: mysql> select * from SmsTest where phoneNo between 30 and 40 for update;
+-------+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+-------+---------+-------------+--------+
| 30 | 30 | 2 | 1 |
| 45292 | 30 | 1 | 1 |
| 31 | 31 | 2 | 1 |
| 32 | 32 | 2 | 1 |
| 33 | 33 | 2 | 1 |
| 34 | 34 | 2 | 1 |
| 35 | 35 | 2 | 1 |
| 36 | 36 | 2 | 1 |
| 37 | 37 | 2 | 1 |
| 38 | 38 | 2 | 1 |
| 39 | 39 | 2 | 1 |
| 40 | 40 | 2 | 1 |
+-------+---------+-------------+--------+
12 rows in set (0.00 sec) mysql> select * from SmsTest where phoneNo between 30 and 40 for update;
+-------+---------+-------------+--------+
| sn | phoneNo | channelType | status |
+-------+---------+-------------+--------+
| 30 | 30 | 2 | 1 |
| 45292 | 30 | 1 | 1 |
| 31 | 31 | 2 | 1 |
| 45293 | 31 | 1 | 1 |
| 32 | 32 | 2 | 1 |
| 33 | 33 | 2 | 1 |
| 34 | 34 | 2 | 1 |
| 35 | 35 | 2 | 1 |
| 36 | 36 | 2 | 1 |
| 37 | 37 | 2 | 1 |
| 38 | 38 | 2 | 1 |
| 39 | 39 | 2 | 1 |
| 40 | 40 | 2 | 1 |
+-------+---------+-------------+--------+
13 rows in set (0.01 sec) 结论 RR模式下 需要区间锁来防止幻读, RC模式下,没有区间锁,会出现幻读

RR模式下利用区间锁防止幻读,RC模式没有区间锁会出现幻读的更多相关文章

  1. x86架构:保护模式下利用中断实现抢占式多任务运行

         站在用户角度考虑,一个合格的操作系统即使在单核下也能 "同时" 执行多个任务,这就要求CPU以非常快的频率在不同任务之间切换,让普通人根本感觉不到任务的切换.windwo ...

  2. Myeclipse在debug模式下没加断点程序卡住,start模式下可以正常启动

    参考<eclipse在debug模式下卡住,start模式下可以启动>,地址:https://blog.csdn.net/jack_chen1994/article/details/761 ...

  3. 使用eclipse启动tomcat,正常模式下可以启动tomcat,却在debug模式下无法启动tomcat 问题解决

    这个问题可能是由于eclipse和tomcat的交互而产生的,在以debug模式启动tomcat时,发生了读取文件错误,eclipse自动设置了断点,导致tomcat不能正常启动. 解决方法把brea ...

  4. 16位模式/32位模式下PUSH指令探究——《x86汇编语言:从实模式到保护模式》读书笔记16

    一.Intel 32 位处理器的工作模式 如上图所示,Intel 32 位处理器有3种工作模式. (1)实模式:工作方式相当于一个8086 (2)保护模式:提供支持多任务环境的工作方式,建立保护机制 ...

  5. 用VMWare搭建服务器集群不能上外网的三种模式下对应解决办法

    前言 决心要花费宝贵时间写下这篇心得,是因为从昨天晚上到今天上午被这个VMWare模拟搭建的服务器集群不能上外网的问题搞得很心烦,最后决定跟它杠上了!上午还通过远程连接得到了“空白”同学的帮助,在此表 ...

  6. MVVM模式下弹出窗体

    原地址:http://www.cnblogs.com/yk250/p/5773425.html 在mvvm模式下弹出窗体,有使用接口模式传入参数new一个对象的,还有的是继承于一个window,然后在 ...

  7. CFUpdate高速模式下出现Error #2038提示的解决方案

    使用CFUpdate上传文件,在IE模式下是正常的,切换到高速模式下出现提示Error #2038错误,文件无法上传. 向作者了解到需要设置challs_flash_update函数中的a.url为绝 ...

  8. sql server 备份与恢复系列五 完整模式下的备份与还原

    一.概述 前面介绍了简单恢复模式和大容量恢复模式,这篇继续写完整恢复模式下的备份与还原.在完整恢复模式里最大的优点是只要能成功备份尾日志,就可以还原到日志备份内包含的任何时点("时点恢复&q ...

  9. eclipse的debug模式下启动不了tomcat

    使用eclipse启动tomcat,正常模式下可以启动tomcat,却在debug模式下无法启动tomcat. 这个问题可能是由于eclipse和tomcat的交互而产生的,在以debug模式启动to ...

随机推荐

  1. CHAR 详解

    CHAR(20):20指的是表中的a字段能存储的最大字符个数 CREATE TABLE `a` ( `a` char(20) DEFAULT NULL) ENGINE=InnoDB DEFAULT C ...

  2. 慢查询日志 与 general_log

            慢查询日志: 打开慢查询日志: set global slow_query_log=on; 输出格式定义:log_output: [file|table] FILE: set glob ...

  3. 利用systemtap学习Linux路由代码

    http://bbs.chinaunix.net/thread-4090162-1-1.html 一.为什么要这样做读kernel route子系统代码,当我弄懂了数据结构之间的关系以及控制流程后,心 ...

  4. Annotation Type @bean,@Import,@configuration使用--官方文档

    @Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface Bean ...

  5. HTTP协议基础与实验

    一. HTTP协议(Hypetext Transfer Protoacal,超文本传输协议) HTTP协议规定了Web基本的运作过程,以及Web服务器之间的通信细节. Http协议采用客户端/服务器端 ...

  6. 上机实践 - - 一个例子了解C/C++中指针与数组的区别

    本例子来自于<剑指Offer>(P37) 解答如下: size1:20 data1是一个数组,sizeof(data1)是求数组大小. 这个数组包含5个整数,每个整数4个字节,共20字节. ...

  7. 脚本动态监控input

    Jquery $('input').bind('input propertychange', function() { //进行相关操作 }); JS if(isIE) { document.getE ...

  8. SDK Manager.exe 无法启动,一闪而过的解决办法

    删掉 C:\Windows\system32\ 下的 java.exe.javaw.exe.javaws.exe 即可解决.(转载)

  9. Android开发文摘集合1

    作者:张明云 原标题:Android 开发中,有哪些坑需要注意? 作者github主页:zmywly8866.github.io/ 在Android library中不能使用switch-case语句 ...

  10. angularjs ngTable -Custom filter template-calendar

    jsp页面: <script type="text/ng-template" id="path/to/your/filters/top-Date-One.html& ...