detecting locked tables mysql (locked by LOCK TABLE)

detecting locked tables mysql (locked by LOCK TABLE)


up vote15down votefavorite

7

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

mysql locking


share|improve this question

edited Aug 26 ‘12 at 1:36

pero
8,31832755

asked Mar 23 ‘10 at 12:55

Marcin
2,18452553

 

    

Why don‘t you unlock the table first ? –  David V. Mar 23 ‘10 at 13:07
6  

@David V.: I guess because he needs to know it is locked first? Or maybe he want‘s to avoid ‘touching‘ the table when/if it is locked? –  lexu Mar 23 ‘10 at 13:11
    

O_O Ooooh my bad, I read that as "delete" (and deleting in the title) locked tables. –  David V. Mar 23 ‘10 at 13:42

add a comment

5 Answers

activeoldestvotes


up vote1down voteaccepted

You can‘t for non-named locks!

More info: http://forums.mysql.com/read.php?21,222363,223774#msg-223774

Not unless you use an advisory lock first. You might also want to look into using INSERT DELAYED instead.


share|improve this answer

edited Sep 15 at 9:32

answered Apr 5 ‘10 at 18:48

confiq
905719

 
add a comment

Did you find this question interesting? Try our newsletter

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).


up vote29down vote

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


share|improve this answer

answered Apr 5 ‘10 at 18:41

Marc B
203k16128227

 
add a comment

up vote14down vote

Use SHOW OPEN TABLEShttp://dev.mysql.com/doc/refman/5.1/en/show-open-tables.html

You can do something like this

SHOW OPEN TABLES WHERE `Table` LIKE ‘%foo%‘ AND Database LIKE ‘[DBNAME]‘ AND In_use > 0;

to check any locked tables in a database.


share|improve this answer

edited Oct 25 ‘13 at 12:07

borrel
578314

answered Aug 25 ‘12 at 7:10

Aruman
39638

 

3  

Note: I can only get this query to work if I use `Database` instead of just Database –  rinogo Feb 11 at 23:06 

add a comment


up vote3down vote

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!


share|improve this answer

answered Mar 31 ‘10 at 11:07

Giles Smith
1087

 

    

this only works for named locks what about non named locks? –  Marcin Apr 5 ‘10 at 12:32
    

You can‘t for non named locks –  Giles Smith Apr 6 ‘10 at 16:31

add a comment


up vote0down vote

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


share|improve this answer

edited Mar 23 ‘10 at 13:12

answered Mar 23 ‘10 at 13:06

Tomislav Nakic-Alfirevic
5,76211735

 

1  

its fine but what about MyISAM being locked ? cheers –  Marcin Mar 23 ‘10 at 13:56
    

Sorry, can‘t help you there. –  Tomislav Nakic-Alfirevic Mar 23 ‘10 at 15:02

http://stackoverflow.com/questions/2499976/detecting-locked-tables-mysql-locked-by-lock-table

时间: 2024-12-24 03:05:48

detecting locked tables mysql (locked by LOCK TABLE)的相关文章

MySQL出现Waiting for table metadata lock的原因以及解决方法

转自:http://ctripmysqldba.iteye.com/blog/1938150 (有修改) MySQL在进行alter table等DDL操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的操作停滞在Waiting for table metadata lock的状态,后续对TableA的任何操作(包括读)都无法进行,因为他们也会在Opening tables的阶段进入到Waiting for

【MySQL笔记】mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法

step1:查看 1.1 Mysql命令行里输入"show engines:"查看innoddb数据引擎状态, 1.2 show variables "%_buffer%"里查看innodb_buffer_pool_size的数值,默认是8M(太小,需要改大一点!) step2:找配置文件,修改innodb_buffer_pool_size=64M 2.1 在linux里配置文件是my.cnf,windows里是my.ini(注:不是my-default.ini).

MySQL出现Waiting for table metadata lock的原因以及解决方法(转)

MySQL在进行alter table等DDL操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的操作停滞在Waiting for table metadata lock的状态,后续对TableA的任何操作(包括读)都无法进行,因为他们也会在Opening tables的阶段进入到Waiting for table metadata lock的锁等待队列.如果是产品环境的核心表出现了这样的锁等待队列,就会造成

MYSQL碰到The total number of locks exceeds the lock table size 问题解决记录

解决记录如下: 在mysql里面进行修改操作时提示:The total number of locks exceeds the lock table size ,通过百度搜到innodb_buffer_pool_size过小: 打开mysql 命令框 输入 show variables like "%tmp%"; 查看innodb_buffer_pool_size,输入SET GLOBAL innodb_buffer_pool_size=67108864; 完成之后再次使用show v

innodb table level lock 与lock table语句关系

DDL语句只申请意向级别的表锁.在lock table语句中,mysql会申请mysql级别表锁,同时innodb也会申请innodb级别表锁.前提是innodb_table_locks=1 https://www.percona.com/blog/2012/07/31/innodb-table-locks/ MySQL Table level locks and Innodb Table Levellocks are two separate beings. You almost never

A MySQL foreign keys drop table, re-create table example

Summary: How to drop MySQL database tables and recreate them when you have foreign keyrelationships between the tables. This is pretty obscure, but I thought I'd post it here so I wouldn't forget how to do this ... if you ever have a situation when u

Mysql_解决The total number of locks exceeds the lock table size错误

在操作mysql数据库表时出现以下错误. 网上google搜索相关问题,发现一位外国牛人这么解释: If you're running an operation on a large number of rows within a table that uses the InnoDB storage engine, you might see this error: ERROR 1206 (HY000): The total number of locks exceeds the lock ta

MYSQL导入数据:Table XXX doesn't exist的解决

数据表为Innodb引擎 data文件夹中存在数据表的frm文件,但在phpmyadmin中看不到这些表,于是采用导入sql文件的方式进行恢复 1.直接导入原数据表的sql文件,原frm文件不删除 出错:#1146 - Table 'eticket.et_admin' doesn't exist 2.删除原frm文件,刷新phpmyadmin,再导入该数据表的sql文件 出错:#1146 - Table 'eticket.et_admin' doesn't exist 3.删除原frm文件,重启

mysql报【unknown table in mulit delete】错的原因和解决办法

今天写一个多表连接删除的DELETE语句,在执行的时候发现报错:unknown table in mulit delete,这里记录下原因. 原来报错的DELETE语句: delete sys_project from sys_project as aa left join ( select min(id) as id from sys_project group by sysCode ) as bb on aa.id = bb.id where bb.id is null 要注意的是,这样的语