mysql abnormal Lock wait timeout exceeded Analysis

Copyright: https://blog.csdn.net/qq_35548458/article/details/90695143

In the code debug mode, debug business processes encountered

  java.lang.Exception:
    ### Error updating database.  Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

abnormal;

Analysis : "LOCK WAIT" transactions occurred while performing the update sql statement.

Specifically, it is this:

When a request for a transaction A recording operation is not update or delete the commit, still in the debug in another transaction B (browsers) recording an update or delete operation, then a transaction before the transaction to the waiting B a transaction is committed, the release row locks, if this time exceeds the timeout mysql settings will produce "lOCK WAIT" affairs.

Solution :

Mysql execute the command: SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;

Find trx_state to "LOCK WAIT" record, according to the system of records in the query id (trx_mysql_thread_id): kill off the thread id is locked

KILL trx_mysql_thread_id ;

This is a request will appear in the case of "LOCL_WAIT" of;

When no other program requests a database, execute mysql command SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;

In addition to the findings a "LOCK_WAIT" record, there are two corresponding "RUNNING" record, all disposable simply kill after off.

The problem is solved.

Code of Repairing: 1 in the sql code module has added things, and specified timeout;.

@Transactional( rollbackFor = Exception.class , isolation = Isolation.REPEATABLE_READ, timeout = 30)

SQL optimization : 2, bulk modify transaction exists, delete the statements, when, where conditions try to add index

Guess you like

Origin blog.csdn.net/qq_35548458/article/details/90695143