一、show processlist;mysql
SHOW PROCESSLIST顯示哪些線程正在運行。您也能夠使用mysqladmin processlist語句獲得此信息。若是您有SUPER權限,您能夠看到全部線程。不然,您只能看到您本身的線程(也就是,與您正在使用的MySQL帳戶相關的線程)。若是有線程在update或者insert 某個表,此時進程的status爲updating 或者 sending data。
若是您獲得「too many connections」錯誤信息,而且想要了解正在發生的狀況,本語句是很是有用的。MySQL保留一個額外的鏈接,讓擁有SUPER權限的帳戶使用,以確保管理員可以隨時鏈接和檢查系統(假設您沒有把此權限給予全部的用戶)。sql
大部分狀態對應很快的操做,只要有一個線程保持同一個狀態好幾秒鐘,那麼多是有問題發生了,須要檢查一下。還有其餘的狀態沒在上面中列出來,不過它們大部分只是在查看服務器是否有存在錯誤是才用得着。數據庫
二、show full processlist;服務器
show processlist;只列出前100條,若是想全列出請使用show full processlist;oop
三、show open tables;spa
mysql> show open tables from gongzhang_testx; +-----------------+-----------------------------+--------+-------------+ | Database | Table | In_use | Name_locked | +-----------------+-----------------------------+--------+-------------+ | gongzhang_testx | gz_news | 0 | 0 | | gongzhang_testx | gz_exam_sub_log | 0 | 0 | | gongzhang_testx | gz_chief_list_tmp | 0 | 0 | | gongzhang_testx | gz_comment | 0 | 0 | | gongzhang_testx | gz_counsel | 0 | 0 | | gongzhang_testx | gz_contract_jianli_pay | 0 | 0 | | gongzhang_testx | gz_focus | 0 | 0 | | gongzhang_testx | gz_city | 0 | 0 | | gongzhang_testx | gz_chief_goods_bss | 0 | 0 |
這條命令可以查看當前有那些表是打開的。In_use列表示有多少線程正在使用某張表,Name_locked表示表名是否被鎖,這通常發生在Drop或Rename命令操做這張表時。因此這條命令不能幫助解答咱們常見的問題:當前某張表是否有死鎖,誰擁有表上的這個鎖等。這個列表可能特別長,你的屏幕估計都裝不下。我遇到過,滾動條翻到最上面仍是顯示不了第一行,因此能夠考慮使用客戶端軟件查看。或者經過指定數據庫來減小返回條數:show open tables from database;線程
四、show status like ‘%lock%’code
查看服務器狀態。orm
mysql> show status like '%lock%'; +------------------------------------------+---------+ | Variable_name | Value | +------------------------------------------+---------+ | Com_lock_tables | 0 | | Com_unlock_tables | 0 | | Innodb_row_lock_current_waits | 0 | | Innodb_row_lock_time | 3946985 | | Innodb_row_lock_time_avg | 1558 | | Innodb_row_lock_time_max | 121788 | | Innodb_row_lock_waits | 2532 | | Key_blocks_not_flushed | 0 | | Key_blocks_unused | 26716 | | Key_blocks_used | 2660 | | Performance_schema_locker_lost | 0 | | Performance_schema_rwlock_classes_lost | 0 | | Performance_schema_rwlock_instances_lost | 0 | | Qcache_free_blocks | 27343 | | Qcache_total_blocks | 61962 | | Table_locks_immediate | 8504599 | | Table_locks_waited | 2 | +------------------------------------------+---------+
五、show engine innodb status\G;blog
*************************** 1. row *************************** Type: InnoDB Name: Status: ===================================== 171221 12:09:47 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 47 seconds ----------------- BACKGROUND THREAD ----------------- srv_master_thread loops: 339595 1_second, 339207 sleeps, 30987 10_second, 31236 background, 31233 flush srv_master_thread log flush and writes: 343088 ---------- SEMAPHORES ---------- OS WAIT ARRAY INFO: reservation count 59209, signal count 73914 Mutex spin waits 243814, rounds 785599, OS waits 12909 RW-shared spins 58108, rounds 1500837, OS waits 40638 RW-excl spins 7233, rounds 212962, OS waits 4938 Spin rounds per wait: 3.22 mutex, 25.83 RW-shared, 29.44 RW-excl ------------ TRANSACTIONS ------------ Trx id counter 3502909
MySQL 5.1以前的命令是:show innodbstatus\G;,MySQL 5.5使用上面命令便可查看innodb引擎的運行時信息。使用「\G」 能夠改成縱向列出,查看更方便。
六、show variables like '%timeout%'
查看服務器配置參數
mysql> show variables like '%timeout%'; +----------------------------+----------+ | Variable_name | Value | +----------------------------+----------+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | innodb_lock_wait_timeout | 120 | | innodb_rollback_on_timeout | OFF | | interactive_timeout | 28800 | | lock_wait_timeout | 31536000 | | net_read_timeout | 30 | | net_write_timeout | 60 | | slave_net_timeout | 3600 | | wait_timeout | 28800 | +----------------------------+----------+
七、SELECT * FROM information_schema.INNODB_TRX
查詢 正在執行的事務:
八、SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
查看正在鎖的事務
九、SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
查看等待鎖的事務