MySQL Lock wait analysis "1" in the lock waiting analysis is step by step, although the final analysis came out, but the time is relatively long; after clearing the relationships between the tables, get the following SQL statement for later use
Selectblock_trx.trx_mysql_thread_id asBLOCKING_SESSION_ID,--session ID with lock already held request_trx.trx_mysql_thread_id asrequest_session_id,--the session ID Block_trx.trx_query is requesting a lock asBlocking_sql_text,--The SQL statement that already holds the lock Request_trx.trx_query asRequesting_sql_text,--The SQL statement that is requesting the lock waits.blocking_trx_id asBLOCKING_TRX_ID,--transaction ID with lock already held waits.requesting_trx_id asREQUESTING_TRX_ID,--The transaction ID that is requesting the lock waits.requested_lock_id asREQUESTED_LOCK_ID,--ID of the lock object locks.lock_table asLock_table,--table locked by the lock object Locks.lock_type asLock_type,--Lock Type Locks.lock_mode asLock_mode--Lock Mode fromInformation_schema.innodb_lock_waits asWaitsinner Join Information_schema.innodb_trx asBlock_trx on waits.blocking_trx_id=Block_trx.trx_idinner Join Information_schema.innodb_trx asRequest_trx on waits.requesting_trx_id=Request_trx.trx_idinner Join Information_schema.innodb_locks aslocks on waits.requested_lock_id=locks.lock_id;+---------------------+--------------------+-------------------+-----------------------------------+----------- ------+-------------------+-------------------+--------------+-----------+-----------+| blocking_session_id | request_session_id | Blocking_sql_text | Requesting_sql_text | blocking_trx_id | requesting_trx_id | requested_lock_id | lock_table | Lock_type | Lock_mode |+---------------------+--------------------+-------------------+-----------------------------------+ -----------------+-------------------+-------------------+--------------+-----------+-----------+|1435|1255| NULL |Select* fromtempdb.t forUpdate |26293|26299|26299: -:3:2| ' tempdb '-' t ' | RECORD | X | |1435|1165| NULL | INSERT into t (x) VALUES (3) |26293|26294|26294: -:3:1| ' tempdb '-' t ' | RECORD | X |+---------------------+--------------------+-------------------+-----------------------------------+--------- --------+-------------------+-------------------+--------------+-----------+-----------+
MySQL Lock wait analysis "2"