mysql下事务和锁
2015-12-03 17:09
567 查看
| |||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||
| 同一个事务中 select c from a where a=1 for update 与 select c from a where a=1 取出的值不一样
| ||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||
| 一致性的非锁定读: 通过Undo段实现,不同的隔离级别读取的快照数据不同 多版本并发控制(Multi Version Concurrency Control, MVCC)
| |||||||||||||||||||||||||||||||||||
|
| 事务一 | 事务二 | 结果(更新后 读最新值) |
| start transaction; | | |
| | start transaction; | |
Q1 | | select c from a where a=1; | 0 |
| | update a set c=c+1 where a=1; | |
Q1 | | select c from a where a=1; | 1 |
| | commit; | |
P1 | select c from a where a=1; | | 1 |
| | | |
| 事务一 | 事务二 | 结果(更新后 读最新值) |
| start transaction; | | |
| | start transaction; | |
P1 | select c from a where a=1; | | 0 |
| | update a set c=c+1 where a=1; | |
Q1 | | select c from a where a=1; | 1 |
| update a set c=c+1 where a=1; | | |
| | commit; | |
P2 | select c from a where a=1; | | 3 |
| | | |
| |||||||||||||||||||||
|
| ||||||||||||||||||||
| 写一致性
| ||||||||||||||||||||
|
事务一 | 事务二 | next-key-lock |
begin; | | |
select c from a where a<3 lock in share mode; | | |
| begin; | |
| Insert into a(a) select 1; | 锁等待 |
Commit; | | |
SET [SESSION |GLOBAL] TRANSACTION ISOLATION LEVEL {READ UNCOMMITTED | READ COMMITTED |REPEATABLE READ | SERIALIZABLE}
SET SESSION TRANSACTION ISOLATION LEVELREPEATABLE READ;
相关文章推荐
- MySQL Study之--Percona server 5.5升级5.6
- mysql full join 解决方案
- 使用SSH工具连接到MySQL
- [Mysql数据库] mysql 命令行登录详解
- mysql存储过程详解[转]
- ubuntu 下mysql中文乱码问题解决方案
- mysql完美增量备份脚本
- mysql alter
- MySQL命令行基本命令操作
- navicat for mysql 远程连接数据库时出现2003-Can't connect to Mysql on '主机名'(10061)解决方法
- lnmp mysql高负载优化
- mysql 含反斜杠的字符查询
- mysql性能优化
- MySQL创建SCOTT用户及初始化数据
- mysql中char和varchar有什么区别?
- mysql输出的错误提示是法语
- MySQL 加锁处理分析
- MySQL字符串函数:字符串截取
- MySQL命令大全
- [MySQL复制异常]Cannot execute statement: impossible to write to binary log since statement is in row for