会话1: mysql> FLUSH TABLES WITH READ LOCK; Query OK, 0 rows affected (0.18 sec) mysql> show processlist; +----+------+-----------------+------+---------+------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------------+------+---------+------+----------+------------------+ | 12 | root | localhost:48850 | NULL | Sleep | 3603 | | NULL | | 13 | root | localhost:48851 | test | Sleep | 2665 | | NULL | | 14 | root | localhost:49828 | NULL | Query | 0 | starting | show processlist | +----+------+-----------------+------+---------+------+----------+------------------+ 3 rows in set (0.00 sec) mysql> use test; Database changed mysql> create table tt( a int); ERROR 1223 (HY000): Can‘t execute the query because you have a conflicting read lock
会话2: mysql> use test; Database changed mysql> create table tt(a int);
会话1: mysql> show processlist; +----+------+-----------------+------+---------+------+------------------------------+------------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------------+------+---------+------+------------------------------+------------------------+ | 12 | root | localhost:48850 | NULL | Sleep | 3712 | | NULL | | 13 | root | localhost:48851 | test | Sleep | 2774 | | NULL | | 14 | root | localhost:49828 | test | Query | 0 | starting | show processlist | | 15 | root | localhost:49833 | test | Query | 7 | Waiting for global read lock | create table tt(a int) | +----+------+-----------------+------+---------+------+------------------------------+------------------------+ 4 rows in set (0.00 sec)
1.当退去会话1后,就会自动释放锁,会话2,就可执行 2.unlock table
时间: 2024-11-07 16:46:12