The INNODB_LOCKS table contains information about each lock that an InnoDB transaction has requested but not yet acquired, and each lock that a transaction holds that is blocking another transaction.
|Unique lock ID number, internal to InnoDB. Treat it as an opaque string. Although LOCK_ID currently contains TRX_ID, the format of the data in LOCK_ID is subject to change at any time. Do not write applications that parse the LOCK_ID value.
|ID of the transaction holding the lock. To obtain details about the transaction, join this column with the TRX_ID column of theINNODB_TRX table.
|How the lock is requested. Permitted values are S[,GAP], X[,GAP], IS[,GAP], IX[,GAP], AUTO_INC, and UNKNOWN. Lock modes other than AUTO_INC and UNKNOWN indicate gap locks, if present. For information about S, X, IS, IX, and gap locks, refer to Section 14.8.1, “InnoDB Locking”.
|The type of lock. Permitted values are
RECORD for a row-level lock,
TABLE for a table-level lock.
|Name of the table that has been locked or contains locked records.
|Name of the index, if LOCK_TYPE is RECORD; otherwise NULL.
|Tablespace ID of the locked record, if
|Page number of the locked record, if
|Heap number of the locked record within the page, if LOCK_TYPE is RECORD; otherwise NULL.
|The data associated with the lock, if any. Values are primary key values of the locked record if LOCK_TYPE is RECORD, otherwise NULL. This column contains the values of the primary key columns in the locked row, formatted as a valid SQL string (ready to be copied to SQL statements). If there is no primary key, LOCK_DATA is the unique InnoDB internal row ID number. If a gap lock is taken for key values or ranges above the largest value in the index, LOCK_DATA reports supremum pseudo-record. When the page containing the locked record is not in the buffer pool (in the case that it was paged out to disk while the lock was held), InnoDB does not fetch the page from disk, to avoid unnecessary disk operations. Instead, LOCK_DATA is set to NULL.
The INNODB_LOCK_WAITS table contains one or more rows for each blocked InnoDB transaction, indicating the lock it has requested and any locks that are blocking that request.
|ID of the requesting (blocked) transaction.
|ID of the lock for which a transaction is waiting. To obtain details about the lock, join this column with the LOCK_ID column of theINNODB_LOCKS table.
|ID of the blocking transaction.
|ID of a lock held by a transaction blocking another transaction from proceeding. To obtain details about the lock, join this column with the LOCK_ID column of the INNODB_LOCKS table.
mysql> select * from information_schema.innodb_locks;
输出 innodb 的状态信息，其中有事务的加锁情况
set global innodb_status_output_locks=ON; // 输出的内容包含锁的详细信息
| InnoDB | |