mysql中Lock wait timeout exceeded; try restarting transaction

Posted 蜗牛的信仰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql中Lock wait timeout exceeded; try restarting transaction相关的知识,希望对你有一定的参考价值。

在项目中遇到以下错误

2018-10-30 10:00:02.307 [http-nio-8088-exec-1] ERROR c.s.p.s.e.r.GlobalExceptionResolver -未知异常发生了:
org.springframework.dao.CannotAcquireLockException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
### The error may involve com.sbl.pay.subaccount.dao.OfflineMerchantImgMapper.insert-Inline
### The error occurred while setting parameters
### SQL: insert into sbl_offline_merchant_img (id, createDate, isDel,        modifyDate, taxRegistLicensePic, bankCardOppositePic,        bankCardPositivePic, legalPersonidOppositePic,        legalPersonidPositivePic, letterOfAuthPic,        licensePic, offlineMerchantId, openingAccountLicensePic,        settlePersonIdcardOpposite, settlePersonIdcardPositive,        merchantAgreementPic, storePic, insideScenePic,        businessPlacePic, orgCodePic, handIdcardPic,        leaseAgreementThreePic, leaseAgreementTwoPic,        leaseAgreementOnePic, otherMaterialPictureOne,        otherMaterialPictureTwo, otherMaterialPictureThree,        otherMaterialPictureFour, otherMaterialPictureFive,        agentPersonSignature, confirmPersonSignature,        unionSettleWithoutLicense)     values (?, ?, ?,        ?, ?, ?,        ?, ?,        ?, ?,        ?, ?, ?,        ?, ?,        ?, ?, ?,        ?, ?, ?,        ?, ?,        ?, ?,        ?, ?,        ?, ?,        ?, ?,        ?)
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
; ]; Lock wait timeout exceeded; try restarting transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
   at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:262)
   at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
   at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
   at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
   at com.sun.proxy.$Proxy83.insert(Unknown Source)
   at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
   at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57)
   at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
   at com.sun.proxy.$Proxy104.insert(Unknown Source)
   at com.sbl.pay.subaccount.service.impl.OfflineMerchantImgServiceImpl.insert(OfflineMerchantImgServiceImpl.java:23)
   at com.sbl.pay.subaccount.service.impl.OfflineMerchantImgServiceImpl$$FastClassBySpringCGLIB$$f7bb3845.invoke(<generated>)
   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
   at com.sbl.pay.subaccount.service.impl.OfflineMerchantImgServiceImpl$$EnhancerBySpringCGLIB$$eeb79b89.insert(<generated>)
   at com.sbl.pay.subaccount.service.impl.OfflineMerchantServiceImpl.uploadOrUpdate(OfflineMerchantServiceImpl.java:178)
   at com.sbl.pay.subaccount.service.impl.OfflineMerchantServiceImpl.update(OfflineMerchantServiceImpl.java:414)
   at com.sbl.pay.subaccount.service.impl.OfflineMerchantServiceImpl$$FastClassBySpringCGLIB$$bfa905c2.invoke(<generated>)
   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
   at com.sbl.pay.subaccount.service.impl.OfflineMerchantServiceImpl$$EnhancerBySpringCGLIB$$41fada20.update(<generated>)
   at com.sbl.pay.subaccount.controller.admin.OfflineMerchantAdminController.update(OfflineMerchantAdminController.java:318)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:497)
   at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)
   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)
   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
   at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
   at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468)
   at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Thread.java:745)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
   at com.mysql.jdbc.Util.getInstance(Util.java:408)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:952)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
   at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
   at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
   at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
   at sun.reflect.GeneratedMethodAccessor156.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:497)
   at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
   at com.sun.proxy.$Proxy156.execute(Unknown Source)
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
   at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
   at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:497)
   at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
   at com.sun.proxy.$Proxy154.update(Unknown Source)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:497)
   at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
   ... 85 common frames omitted

Lock wait timeout exceeded; try restarting transaction是锁等待超时。是当前事务在等待其它事务释放锁资源造成的。

解决方法:

在mysql查询中执行以下指令
select * from information_schema.innodb_trx
结果如图:

 

 

找出与其他几个有参数不同的线程,找出他的线程号mysql_thread_id

执行命令kill +线程号即可解决。

以上是关于mysql中Lock wait timeout exceeded; try restarting transaction的主要内容,如果未能解决你的问题,请参考以下文章

设置mysql 事务锁超时时间 innodb_lock_wait_timeout

mysql Lock wait timeout exceeded; try restarting transaction解决

mysql提示 Lock wait timeout exceeded解决办法

mysql被锁住 Lock wait timeout exceeded; try restarting transaction

MySQL报错Lock wait timeout exceeded怎么办

MySQL报错Lock wait timeout exceeded怎么办