索引导致死锁: ...jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try ..

数据库的更新突然无法实现了,导致数据对接不过来

异常如下:

### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
; SQL []; Lock wait timeout exceeded; try restarting transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
2019-05-26 07:22:44.321 |-ERROR [http-nio-8081-exec-2] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/queue-admin].[dispatcherServlet] [181] -| Servlet.service() for servlet [dispatcherServlet] in context with path [/queue-admin] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 61100, active 5, maxActive 10] with root cause
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

出现原因:一个表有一个unique index(唯一索引),当进行更新时都需要使用到这个unique index时,unique index会被锁住。而此时又有另一条语句并发进行更新需要使用到这个unique index,又一次去锁住unique index,导致事务没有提交导致,一直在等待啊+一直在等待,于是导致死锁的产生。

解决办法:

1.减少并发使用unique index

2.使用其它字段或拼接字段(能保证唯一性即可)

3.不使用唯一索引,使用normal index(普通索引)

查看数据库进程

show full processlist

杀死进程:

kill id,例:kill 3990

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值