在InnoDB 1.0版本之前,用户只能通过show full processlist;show engine innodb status等来查看当前数据库中锁的请求,然后再判断事务锁的情况。
在InnoDB 1.0版本开始,在information_schema架构下添加了三张表innodb_trx、innodb_locks、innodb_lock_waits用来查看可能存在的锁问题:
mysql> select
r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, r.trx_query waiting_query, b.trx_id blocking_trx_id,
b.trx_mysql_thread_id blocking_thread, b.trx_query blocking_query
from innodb_lock_waits w inner join innodb_trx b
on b.trx_id=w.blocking_trx_id
inner join innodb_trx r
on r.trx_id = w.requesting_trx_id\G;