1、show processlist;
SHOW PROCESSLIST顯示哪些線程正在運行。您也可以使用mysqladmin processlist語句得到此信息。如果您有SUPER權限,您可以看到所有線程。否則,您只能看到您自己的線程(也就是,與您正在使用的MySQL賬戶相關的線程)。如果有線程在update或者insert 某個表,此時進程的status為updating 或者 sending data。
如果您得到“too many connections”錯誤信息,並且想要了解正在發生的情況,本語句是非常有用的。MySQL保留一個額外的連接,讓擁有SUPER權限的賬戶使用,以確保管理員能夠隨時連接和檢查系統(假設您沒有把此權限給予所有的用戶)。
大部分狀態對應很快的操作,只要有一個線程保持同一個狀態好幾秒鍾,那么可能是有問題發生了,需要檢查一下。還有其他的狀態沒在上面中列出來,不過它們大部分只是在查看服務器是否有存在錯誤是才用得着。
2、show full processlist;
show processlist;只列出前100條,如果想全列出請使用show full processlist;
3、show open tables;
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;
4、show status like ‘%lock%’
查看服務器狀態。
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 | +------------------------------------------+---------+
5、show engine innodb status\G;
*************************** 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” 可以改為縱向列出,查看更方便。
6、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 | +----------------------------+----------+
7、SELECT * FROM information_schema.INNODB_TRX
查詢 正在執行的事務:
8、SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
查看正在鎖的事務
9、SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
查看等待鎖的事務