jdbc mysql innodb 死锁 deadlock_mysql 的一个死锁问题解决

这里说的是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

原文:http://blog.csdn.net/jerrydjy/article/details/41479315

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值