mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| 1 | root | localhost | NULL | Query | 0 | init | show processlist |
| 2 | test | localhost | NULL | Sleep | 43 | | NULL |
+----+------+-----------+------+---------+------+-------+------------------+
2 rows in set (0.00 sec)
mysql>
SESSION 1:
3 | test | localhost | test | Sleep | 25 | | NULL
mysql> create table t7(id int);
Query OK, 0 rows affected (0.33 sec)
mysql> lock table t7 read;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values(1);
ERROR 1100 (HY000): Table 't1' was not locked with LOCK TABLES
SESSION 2:
| 4 | test | localhost | test | Sleep | 10 | | NULL
mysql> insert into t7 values(1); ----HANG
清空/var/log/mysql/mysqld.log ,执行mysqladmin -uroot -p1234567 -h127.0.0.1 debug
Thread database.table_name Locked/Waiting Lock_type
3 test.t7 Locked - read Read lock without concurrent inserts ---持有读锁
4 test.t7 Waiting - write Concurrent insert lock ---被堵塞