查看当前session线程号 mysql> select connection_id(); +-----------------+ | connection_id() | +-----------------+ | 28 | +-----------------+ 1 row in set (0.02 sec) Session 1: Vsftp:/root# mysql -uroot -p1234567 -e " show processlist" Warning: Using a password on the command line interface can be insecure. +----+------+-----------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+------------------+ | 17 | root | localhost | zjzc | Sleep | 0 | | NULL | mysql 进程1737 root 1737 979 0 13:02 pts/1 00:00:00 mysql -uroot -px xxxxx mysql> start transaction; Query OK, 0 rows affected (0.00 sec) mysql> delete from test where id=1; Query OK, 1 row affected (0.00 sec) Session 2: | 28 | root | localhost | zjzc | Sleep | 2 | | NULL 查看堵塞: mysql[192.168.11.187] blocking_thread[17] blocking_query[] blocking waiting_thread[28]'s delete from test where id=1 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 -> information_schema.innodb_lock_waits w -> INNER JOIN -> information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id -> INNER JOIN -> information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id; +----------------+----------------+-----------------------------+-----------------+-----------------+----------------+ | waiting_trx_id | waiting_thread | waiting_query | blocking_trx_id | blocking_thread | blocking_query | +----------------+----------------+-----------------------------+-----------------+-----------------+----------------+ | 112076626 | 28 | delete from test where id=1 | 112076625 | 17 | NULL | +----------------+----------------+-----------------------------+-----------------+-----------------+----------------+ 1 row in set (0.00 sec) Session 1:运行 mysql> select * from ClientActionTrack20151125 mysql[192.168.11.187] blocking_thread[17] blocking_query[select * from ClientActionTrack20151125] blocking waiting_thread[28]'s delete from test where id=1 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 information_schema.innodb_lock_waits w INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id; +----------------+----------------+-----------------------------+-----------------+-----------------+-----------------------------------------+ | waiting_trx_id | waiting_thread | waiting_query | blocking_trx_id | blocking_thread | blocking_query | +----------------+----------------+-----------------------------+-----------------+-----------------+-----------------------------------------+ | 112076626 | 28 | delete from test where id=1 | 112076625 | 17 | select * from ClientActionTrack20151125 | +----------------+----------------+-----------------------------+-----------------+-----------------+-----------------------------------------+ 1 row in set (0.39 sec) 结论: blocking_query 是当前堵塞其他会话正在运行的SQL.而不是原始堵塞SQL