简体   繁体   中英

Get locked tables in mysql query

Is there any way via a MySQL query to get the locked tables? I have a C# threading application running and there are bunch of tables getting locked in the app.

I need to see the locked tables and analyze the code that could be locking it.

Use:

SHOW OPEN TABLES

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

Examples

  • List of locked tables:

    show open tables WHERE In_use > 0

  • Check whether the table tb_employees is locked or not:

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

From the official documentation :

In_use

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM