MySQL查看鎖表的狀態命令


MySQL查看鎖表的狀態命令

1、mysql 查看鎖表解鎖

-- 查看那些表鎖到了 show open tables where in_use > 0;
-- 查看進程號 show processlist;
-- 刪除進程 kill 1085850;

2、查詢是否鎖表
show open tables where in_use > 0;
show open tables;

3、 鎖定數據表,避免在備份過程中,表被更新
mysql>lock tables tbl_name read;

4、為表增加一個寫鎖定
mysql>lock tables tbl_name write;

5、 解鎖
unlock tables;

6、查看表的狀態
show status like 'table%';
show status like 'innodb_row_lock%';

注意:該處是鎖定為只讀狀態,語句不區分大小寫

這里還有一些常用的命令。

1、 關閉所有打開的表,強制關閉所有正在使用的表
flush tables

2、關閉所有打開的表並使用全局讀鎖鎖定所有數據庫的所有表
flush tables with read lock;

3、如果一個會話中使用lock tables tbl_name lock_type語句對某表加了表鎖,在該表鎖未釋放前,那么另外一個會話如果執行flush tables語句會被阻塞,執行flush tables with read lock也會被堵塞

show status like 'innodb_row_lock%';

show status like 'table%';
Table_locks_immediate表示立即釋放表鎖數,
Table_locks_waited表示需要等待的表鎖數,
Table_locks_immediate / Table_locks_waited > 5000,最好采用InnoDB引擎,

因為InnoDB是行鎖而MyISAM是表鎖,對於高並發寫入的應用InnoDB效果會好些。
示例中的服務器Table_locks_immediate / Table_locks_waited = 235,MyISAM就足夠了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM