mysql中查看sql语句的加锁信息

打开开关innodb_lock_monitor用来查看一条语句执行的时候,使用命令show engine innodb status对系统中的lock信息。

开启
mysql> use marketing
Database changed
mysql>

mysql> create table innodb_lock_monitor(x int) engine=innodb;
Query OK, 0 rows affected (0.08 sec)

mysql> exit
Bye
关闭
mysql> use marketing
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> drop table innodb_lock_monitor;
Query OK, 0 rows affected (0.02 sec)

然后使用show engine innodb status进行显示,关于lock的部分是

---TRANSACTION 31C, ACTIVE 42 sec
2 lock struct(s), heap size 320, 6 row lock(s)
MySQL thread id 2, OS thread handle 0x1220, query id 128 localhost 127.0.0.1 root
Trx read view will not see trx with id >= 31D, sees < 31D
TABLE LOCK table `test`.`ta` trx id 31C lock mode IX   (-------------对表加了IX意向锁)
RECORD LOCKS space id 0 page no 312 n bits 72 index `GEN_CLUST_INDEX` of table `test`.`ta` trx id 31C lock_mode X(对以下的行加了X锁)
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
 0: len 8; hex 73757072656d756d; asc supremum;;

Record lock, heap no 2 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 6; hex 000000000203; asc       ;;
 1: len 6; hex 00000000030a; asc       ;;
 2: len 7; hex 8b000001390110; asc     9  ;;
 3: len 4; hex 80000003; asc     ;;
 4: SQL NULL;

Record lock, heap no 3 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 6; hex 000000000204; asc       ;;
 1: len 6; hex 00000000030a; asc       ;;
 2: len 7; hex 8b00000139011e; asc     9  ;;
 3: len 4; hex 80000004; asc     ;;
 4: SQL NULL;

Record lock, heap no 4 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 6; hex 000000000205; asc       ;;
 1: len 6; hex 00000000030a; asc       ;;
 2: len 7; hex 8b00000139012c; asc     9 ,;;
 3: len 4; hex 80000005; asc     ;;
 4: SQL NULL;

Record lock, heap no 5 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 6; hex 000000000206; asc       ;;
 1: len 6; hex 000000000312; asc       ;;
 2: len 7; hex 900000013f0110; asc     ?  ;;
 3: len 4; hex 8000000b; asc     ;;
 4: len 4; hex 8000000c; asc     ;;

Record lock, heap no 6 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 6; hex 00000000020c; asc       ;;
 1: len 6; hex 000000000316; asc       ;;
 2: len 7; hex 94000001420110; asc     B  ;;
 3: len 4; hex 8000000c; asc     ;;
 4: len 4; hex 8000000d; asc     ;;

posted @ 2012-08-20 15:43  Jack204  阅读(10973)  评论(0编辑  收藏  举报