索引导致死锁: ...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

索引导致死锁: ...jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try .._第1张图片

杀死进程:

kill id,例:kill 3990

你可能感兴趣的:(SQL)