mysql innodb 行锁解锁后出现1213 死表现象 Deadlock found when
来源:互联网 发布:python和java的区别 编辑:程序博客网 时间:2024/06/01 10:25
[Err] 1213 - Deadlock found when trying to get lock; try restartingtransaction
出现这个原因要记住一点就是:innodb的行锁和解锁都是针对主键索引的。如果查询时根据索引锁表,但更新时却不是通过主键更新,那么等待的解锁查询的进程将会报1213错误,程序里有可能返回一个null值
实例:
table
soldgoods (表名)
soldgoodsID 索引
productid
businessid
开启线程A
执行:
set autocommit=0;
select businessid from soldgoods where soldgoodsID ='ac63837c76222e4a5419e2529d775ae4' for UPDATE;
查询得过结果
开启线程B
执行:
set autocommit=0;
select businessid from soldgoodswhere soldgoodsID = 'ac63837c76222e4a5419e2529d775ae4' forUPDATE;
查询等待解锁
这个时候在线程A中执行:
update soldgoods set productid = 2 where businessid ='0a527df4763c3dc71cbafebec5a8d787'
不是根据主键而去更新锁表的值
线程B会出现:
[Err] 1213 - Deadlock found when trying to get lock; tryrestarting transaction
如果将最后线程A中执行的语句改变:
update soldgoods setproductid = 2 where soldgoodsID ='ac63837c76222e4a5419e2529d775ae4'
根据索引修改值
然后
commit;
提交事务。线程B就能顺利得到查询值了
原文参考:http://blog.sina.com.cn/s/blog_4acbd39c01014gsq.html
阅读全文
0 0
- mysql innodb 行锁解锁后出现1213 死表现象 Deadlock found when
- mysql innodb 行锁解锁后出现1213 死表现象 Deadlock found when
- mysql innodb 行锁解锁后出现1213 死表现象 Deadlock found when
- mysql innodb 事务操作的表锁及行锁-Deadlock found when trying to get lock; try restarting transaction的优化
- mysql innodb hibernate Deadlock
- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when tryin
- mysql数据库死锁:Deadlock found when trying to get lock; try restarting transaction
- SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting
- Mysql innodb 分析定位DeadLock的方法
- Deadlock found when trying to get lock; try restarting transaction
- deadlock found when trying to get lock ;try restarting transaction
- oracle 用户锁死解锁
- grails Deadlock found when trying to get lock; try restarting transaction
- MySql deadlock
- fragment在锁屏解锁后出现重新onCreate解决办法
- deadlock引起数据库挂死
- MySQL innodb行锁测试
- Mysql innodb行锁测试
- bzoj 2375: 疯狂的涂色
- java/Kotlin/android 判断是否是url 的正则
- leetcode算法刷题
- C# 中的线程安全集合类
- mysql学习笔记
- mysql innodb 行锁解锁后出现1213 死表现象 Deadlock found when
- 基于condition 实现的线程安全的优先队列(python实现)
- 从零开始搭建一个项目框架MVVM(OC)
- 测量View的宽高,避免为零
- 蓝牙 Mesh会是最好的物联网协议吗?
- Java引用类型 Java类型转换疑惑
- python 3下基于select模型的事件驱动机制程序
- MySQL--子查询
- 正则表达式-字符串分割