Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check specific table is locked in Mysql?

Tags:

mysql

I am executing below query to find the whether my temp table is locked.

show open tables where in_use > 0 and table = 'temp'

But it throwing below error :

Syntax error near 'table = 'temp'

I have searched but unable to get the correct syntax. Can anybody help.

like image 709
Pratik Avatar asked Oct 27 '25 17:10

Pratik


1 Answers

Approach1: Simply execute command show processlist; or show full processlist; command and check if any query/table is showing locked in processlist.

Note: check from super user to check all running process on server.

Approach2: execute show engine innodb status; and you can check locking here...

Approach3: In mysql 5.6 onwards you can check it in information_schema db also.

Note: If you are using any gui tools like mysqladministrator then you can check all running process in this and easy findout if any table is locked....

Update:

As you want to get this by sql query, so you can use below query-

For all locked tables-

SHOW OPEN TABLES WHERE in_use>0;

To check specific table-

SHOW OPEN TABLES WHERE in_use>0 AND `Table`='your_table_name';
like image 154
Zafar Malik Avatar answered Oct 30 '25 06:10

Zafar Malik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!