Detecting locked tables (locked by LOCK TABLE)

前端 未结 8 1648
野趣味
野趣味 2020-11-29 18:46

Is there a way to detect locked tables in MySQL? I mean tables locked by the LOCK TABLE table WRITE/READ command.

(Note that readers interested in

8条回答
  •  温柔的废话
    2020-11-29 19:42

    You can create your own lock with GET_LOCK(lockName,timeOut)

    If you do a GET_LOCK(lockName, 0) with a 0 time out before you lock the tables and then follow that with a RELEASE_LOCK(lockName) then all other threads performing a GET_LOCK() will get a value of 0 which will tell them that the lock is being held by another thread.

    However this won't work if you don't have all threads calling GET_LOCK() before locking tables. The documentation for locking tables is here

    Hope that helps!

提交回复
热议问题