简体   繁体   English

java.sql.SQLException:超出了锁定等待超时; 尝试重新启动事务异常在MYSQL中发生

[英]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.

相关问题 超过了锁定等待超时; 尝试使用spring和Mysql重新启动事务Java - Lock wait timeout exceeded; try restarting transaction Java with spring and Mysql MySQL错误:超过了锁定等待超时; 尝试重新启动事务查询 - MySQL Error: Lock wait timeout exceeded; try restarting transaction Query 发出java.lang.Exception:超出了锁定等待超时; 尝试重新启动事务 - Issue java.lang.Exception: Lock wait timeout exceeded; try restarting transaction 由于“超过了锁定等待超时,导致事务失败; 尝试重新开始交易” - Transactions fails due to “Lock wait timeout exceeded; try restarting transaction” 超过锁定等待超时; 尝试使用JDBC重新启动事务 - Lock wait timeout exceeded; try restarting transaction using JDBC 超过了锁定等待超时; 尝试在spring_Hibernate_Mysql中重新启动事务 - Lock wait timeout exceeded; try restarting transaction in spring_Hibernate_Mysql 如何修复 Mysql 表之前工作时的“超出锁定等待超时;尝试重新启动事务”? - How to fix "Lock wait timeout exceeded; try restarting transaction" for Mysql table when it was working before? 获取WARN:SQL错误:1205,SQLState:41000错误:超出锁定等待超时; 尝试重新启动事务。 使用休眠保存记录 - Getting WARN: SQL Error: 1205, SQLState: 41000 ERROR: Lock wait timeout exceeded; try restarting transaction. Saving a record in using hibernate 如何解决java.sql.SQLException等待锁定的分布式事务 - How to resolve java.sql.SQLException distributed transaction waiting for lock 无法获取锁定异常:锁定等待超时超过Spring SQL - Cannot aquire lock exception: lock wait timeout exceeded spring sql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM