您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql的一个死锁问题解决_MySQL

2025/4/9 13:20:25发布22次查看
这里说的是innodb类型的死锁!
网上找了好多东西 各种命令查看死锁信息,后面这条能用:
show engine innodb status;(根据mysql版本而异)
这命令在mysql命令行执行后如果有死锁
会出现下面这一块:
------------------------
latest detected deadlock
------------------------
然后你可以根据这块内容找到你引起死锁的语句。
然后解决它,
我这次的死锁是因为,
有这么一条语句
update 表名 set xx=xxx where xxx=xxx!
其中xxx没有索引!
innodb是行级锁,但是mysql的机制是用索引来找到该行,如果你那个where字段没有索引,那么mysql就找不到那一行,就会锁整张表了
这样后面的访问就会引发死锁!
给xxx字段加上索引
解决问题。
附上异常信息:
caused by: org.springframework.dao.deadlockloserdataaccessexception: sqlmapclient operation; sql [];
--- the error occurred while applying a parameter map.
--- check the point.updatepointaccount-inlineparametermap.
--- check the statement (update failed).
--- cause: com.mysql.jdbc.exceptions.mysqltransactionrollbackexception: deadlock found when trying to get lock; try restarting transaction; nested exception is com.ibatis.common.jdbc.exception.nestedsqlexception:
--- the error occurred while applying a parameter map.
--- check the point.updatepointaccount-inlineparametermap.
--- check the statement (update failed).
--- cause: com.mysql.jdbc.exceptions.mysqltransactionrollbackexception: deadlock found when trying to get lock; try restarting transaction
at org.springframework.jdbc.support.sqlerrorcodesqlexceptiontranslator.translate(sqlerrorcodesqlexceptiontranslator.java:300)
at org.springframework.orm.ibatis.sqlmapclienttemplate.execute(sqlmapclienttemplate.java:212)
at org.springframework.orm.ibatis.sqlmapclienttemplate.update(sqlmapclienttemplate.java:411)
at com.hsd.popularize.dao.basedaoimpl.update(basedaoimpl.java:162)
... 87 more
caused by: com.ibatis.common.jdbc.exception.nestedsqlexception:
--- the error occurred while applying a parameter map.
--- check the point.updatepointaccount-inlineparametermap.
--- check the statement (update failed).
--- cause: com.mysql.jdbc.exceptions.mysqltransactionrollbackexception: deadlock found when trying to get lock; try restarting transaction
at com.ibatis.sqlmap.engine.mapping.statement.generalstatement.executeupdate(generalstatement.java:91)
at com.ibatis.sqlmap.engine.impl.sqlmapexecutordelegate.update(sqlmapexecutordelegate.java:505)
at com.ibatis.sqlmap.engine.impl.sqlmapsessionimpl.update(sqlmapsessionimpl.java:90)
at org.springframework.orm.ibatis.sqlmapclienttemplate$10.doinsqlmapclient(sqlmapclienttemplate.java:413)
at org.springframework.orm.ibatis.sqlmapclienttemplate.execute(sqlmapclienttemplate.java:209)
... 89 more
caused by: com.mysql.jdbc.exceptions.mysqltransactionrollbackexception: deadlock found when trying to get lock; try restarting transaction
at com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:941)
at com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:2870)
at com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:1573)
at com.mysql.jdbc.serverpreparedstatement.serverexecute(serverpreparedstatement.java:1169)
at com.mysql.jdbc.serverpreparedstatement.executeinternal(serverpreparedstatement.java:693)
at com.mysql.jdbc.preparedstatement.execute(preparedstatement.java:794)
at com.mchange.v2.c3p0.impl.newproxypreparedstatement.execute(newproxypreparedstatement.java:989)
at sun.reflect.generatedmethodaccessor51.invoke(unknown source)
at sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)
at java.lang.reflect.method.invoke(method.java:606)
at com.ibatis.common.jdbc.logging.preparedstatementlogproxy.invoke(preparedstatementlogproxy.java:62)
at com.sun.proxy.$proxy20.execute(unknown source)
at com.ibatis.sqlmap.engine.execution.sqlexecutor.executeupdate(sqlexecutor.java:81)
at com.ibatis.sqlmap.engine.mapping.statement.generalstatement.sqlexecuteupdate(generalstatement.java:200)
at com.ibatis.sqlmap.engine.mapping.statement.generalstatement.executeupdate(generalstatement.java:78)
... 93 more
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product