14.3.5.1 Interaction of Table Locking and Transactions  表锁和事务的相互作用

LOCK TABLES 和UNLOCK TABLES  交互实用事务如下:

1. LOCK TABLES 不是事务安全的和隐式提交任何活动的事务 在尝试锁定表前

2.UNLOCK TABLES 隐式提交任何活动事务,但是只有如果LOCK TABLES 已经用于获得table locks.

比如, 下面的语句集,UNLOCK TABLES 释放全局锁 但是不会提交事务 因为没有表锁定是生效的。

FLUSH TABLES WITH READ LOCK;
START TRANSACTION;
SELECT ... ;
UNLOCK TABLES; 开始一个事务(例如,START TRANSACTION) 隐式的提交任何当前的事务和释放存在表锁 FLUSH TABLES WITH READ LOCK 需要一个全局的read lock ,不是table locks, 因此它不是服从于相同的行为作为LOCK TABLES 和UNLOCK TABLES 遵守表锁定和隐式提交。 比如, START TRANSACTION 不会释放全局read lock 正确的方式使用LOCK TABLES 和UNLOCK TABLES 在事务表,比如InnoDB 表, 是开始一个事务 设置autocommit = 0(不是START TRANSACTION)跟着lock tables, 不需要调用UNLCOK TABLES 直到你显示的提交事务 SET autocommit=0;
LOCK TABLES t1 WRITE, t2 READ, ...;
... do something with tables t1 and t2 here ...
COMMIT;
UNLOCK TABLES; 当你调用LOCK TABLES时,InnoDB 内部占用它自己的表锁,和MySQL 占用它自己的表锁。 InnoDB 释放它内部表锁 在下次提交时,但是MySQL 释放它的表锁,你需要调用UNLOCK TABLES. 你不能设置autocommit = 1, 因为InnoDB 释放它的内部的table lock 立即在调用LOCK TABLES之后, deadlocks 可以很轻易的发生。InnoDB 不需要获得内部表锁 如果 autocommit = 1, ROLLBACK does not release table locks.

14.3.5.1 Interaction of Table Locking and Transactions 表锁和事务的相互作用的更多相关文章

  1. 14.8.3 Physical Row Structure of InnoDB Tables InnoDB 表的物理行结构

    14.8.3 Physical Row Structure of InnoDB Tables InnoDB 表的物理行结构 一个InnoDB 表的物理行结构取决于在创建表指定的行格式 默认, Inno ...

  2. 学习笔记:ALTERing a Huge MySQL Table - 对一个超大表做alter调整

    Table of Contents The ProblemFuture SolutionsOverview of SolutionShortcutAssumptions/Restrictions/Co ...

  3. 14.7.1 Resizing the InnoDB System Tablespace InnoDB 系统表空间大小

    14.7.1 Resizing the InnoDB System Tablespace InnoDB 系统表空间大小 这个章节描述如何增加或者减少 InnoDB 系统表空间的大小 增加InnoDB ...

  4. 聊下图片滤镜,手机上的,lookup table(颜色查找表

    今天这里要介绍的是lookup table(颜色查找表),简而言之就是通过将每一个原始的颜色进行转换之后成为一个新的颜色. 打一个比方,比如原始颜色是红色(r:255,g:0,b:0),进行转换后变为 ...

  5. mysql学习之-show table status(获取表的信息)参数说明

    --获取表的信息mysql> show table status like 'columns_priv'\G;*************************** 1. row ******* ...

  6. 使用OPTIMIZE TABLE命令来整理表碎片实践

    操作环境:ubuntu 14.10   mysql 5.6.25 对含有BLOB或TEXT字段的表,若经常做修改或删除类的操作,需要定期执行OPTIMIZE TABLE命令来整理碎片. 1.creat ...

  7. 建立简单的Hash table(哈希表)by C language

    #define SIZE 1000 //定义Hash table的初始大小 struct HashArray { int key; int count; struct HashArray* next; ...

  8. Table 类(数据表基类)

    只修改数据表某条记录的部分字段(究极进化): public class TableHelper { private Dictionary<string, object> temp; pub ...

  9. alter table,复制, 单表查询

    修改表 语法:1. 修改表名      ALTER TABLE 表名                           RENAME 新表名; 2. 增加字段      ALTER TABLE 表名 ...

随机推荐

  1. LeetCode_Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  2. C# GC 垃圾回收

    一.托管 .Net所指的托管资源到底是什么意思呢?是相对于所有资源,还是只限于某一方面的资源?很多人对此不是很了解. 其实.Net所指的托管只是针对内存这一个方面,并不是对于所有的元素:因此对于Str ...

  3. 【Xamarin挖墙脚系列:Xamarin 上台讲述PPT呵呵呵】

    http://pan.baidu.com/s/1kUrwQft

  4. 用JSTL简化Java Web开发

    如今这个手中的项目jstl都不要,不方便呢... 链接学习下载:http://c20000001.blog.163.com/blog/static/1154754120088303531450/

  5. LeeCode-Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  6. POJ22230 Watchcow (欧拉回路)

    Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6477   Accepted: 2823   Specia ...

  7. mysql的主从复制原理

    一个简单完整的 Mysql 主从复制,读写分离的示意图. 1. 首先搭建 Mysql 主从架构,实现 将 mater 数据自动复制到 slave MySQL 复制的工作方式很简单,一台服务器作为主机, ...

  8. Eclipse选中变量名,相同变量都变色显示

    Eclipse选中变量名,相同变量都变色显示 java文件的设置"Window"-"preferences"-"Java"-"Ed ...

  9. 关于map与set的一点理解;

    set代码: #include<stdio.h> #include<set> using namespace std; int main(){ set<int>m; ...

  10. HDU 4978 A simple probability problem

    A simple probability problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...