且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在mysql查询中获取锁定表

更新时间:2023-01-29 21:51:18

使用:

SHOW OPEN TABLES

检查列In_use是否大于0.在这种情况下,表被锁定.

An check whether the column In_use is greater than 0. In that case, the table is locked.

  • 锁定表列表:

  • List of locked tables:

show open tables WHERE In_use > 0

检查表tb_employees是否已锁定:

show open tables WHERE Table LIKE 'tb_employees' AND In_use > 0

官方文档:

In_use

In_use

表锁的数量或 该表有锁定请求. 例如,如果一个客户获得了 使用LOCK TABLE t1锁定表 WRITE,In_use将为1.如果另一个 客户端发出LOCK TABLE T1 WRITE 当桌子保持锁定状态时, 客户端将阻止等待 锁定,但锁定请求导致 In_use为2.如果计数为零, 该表已打开,但当前未打开 正在使用.使用量也增加了 由HANDLER ... OPEN语句和 由HANDLER减少... CLOSE.

The number of table locks or lock requests there are for the table. For example, if one client acquires a lock for a table using LOCK TABLE t1 WRITE, In_use will be 1. If another client issues LOCK TABLE t1 WRITE while the table remains locked, the client will block waiting for the lock, but the lock request causes In_use to be 2. If the count is zero, the table is open but not currently being used. In_use is also increased by the HANDLER ... OPEN statement and decreased by HANDLER ... CLOSE.