[英]java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction exception occur in MYSQL
I am Using a table name "test" in MYSQL that is lock during a transaction T1 that will be complete with in 20 minutes. 我在MYSQL中使用表名“ test”,该表在事务T1中被锁定,该事务将在20分钟内完成。 When I am updating this table by another transaction T2 within these 20 minutes .
当我在这20分钟内通过另一个事务T2更新此表时。 I am getting an exception:-
我有一个例外:
11:58:38,584 ERROR [STDERR] java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
11:58:38,584 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
11:58:38,584 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
11:58:38,584 ERROR [STDERR] at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1124)
11:58:38,584 ERROR [STDERR] at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:676)
Please provide me the solution that how can I do this transaction T2 without getting this exception? 请提供解决方案,说明如何在不发生此异常的情况下执行此事务T2?
Is it right to update the value of innodb_lock_wait_timeout in mysql database for solve this exception. 更新mysql数据库中的innodb_lock_wait_timeout的值以解决此异常是否正确。 I look forward for getting any useful solution for this problem .
我期待着获得针对此问题的任何有用的解决方案。
Updating the value of innodb_lock_wait_timeout is not the right way to solve this problem. 更新innodb_lock_wait_timeout的值不是解决此问题的正确方法。 For starters, you it sounds like you would need to update it to 20 minutes, which would be ridiculous.
对于初学者,您听起来好像需要将其更新为20分钟,这太荒谬了。
innodb_lock_wait_timeout has a default of 50 seconds - this is the length of time T2 will wait for access to a table locked by T1 before giving up (and resulting in the exception you are seeing). innodb_lock_wait_timeout的默认值为50秒-这是T2在放弃之前等待等待T1锁定的表的访问的时间(并导致您看到的异常)。
What is your T2 transaction doing? 您的T2交易在做什么? If it is performing reads only (ie not writing to your table "test") then you could change the database's isolation level to "read uncommitted" so that T2 can read the uncommitted data.
如果它仅执行只读操作(即不将其写入表“ test”),则可以将数据库的隔离级别更改为“读取未提交”,以便T2可以读取未提交的数据。 However, IMO this is a hack you should avoid.
但是,IMO这是您应避免的黑客。
Instead, you should consider your design/implementation. 相反,您应该考虑自己的设计/实现。 To have a transaction that is open and holding a row lock for 20 minutes is asking for trouble in a multi-threaded environment (such as a webapp).
要使事务处于打开状态并保持20分钟的行锁,这是在多线程环境(例如webapp)中提出的问题。
Does your archiving activity (which takes 20 minutes) have to be in one transaction? 您的归档活动(需要20分钟)是否必须进行一次交易? An obvious way to solve this problem would be to commit after every statement or to break it into more reasonably sized transactions.
解决此问题的一种明显方法是在每个语句之后提交或将其分解为更合理大小的事务。
重新启动您的本地mysql以避免此类问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.