tags:

views:

696

answers:

4

Hi guys,

I would like to know whether is there an option to detect locked tables in mysql or no. I mean locked by LOCK TABLE table WRITE/READ command ?

cheers,
Marcin

+1  A: 

This article describes how to get information about locked MySQL resources. mysqladmin debug might also be of some use.

Tomislav Nakic-Alfirevic
its fine but what about MyISAM being locked ? cheers
Marcin
Sorry, can't help you there.
Tomislav Nakic-Alfirevic
+1  A: 

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!

Giles Smith
this only works for named locks what about non named locks?
Marcin
You can't for non named locks
Giles Smith
+2  A: 

You can use SHOW OPEN TABLES to show each table's lock status. More details on the command's doc page are here.

Marc B
A: 

You can't for non-named locks !!!! More info: http://forums.mysql.com/read.php?21,222363,223774#msg-223774

confiq