mysql> show global status like '%Com_update%'; //執行更新的個數
mysql> show global status like '%Com_select%'; //執行查詢的個數
mysql> show global status like '%Com_insert%' //執行插入個數
mysql> show global status like '%Com_delect%'; //執行刪除的個數
mysql> show global status like '%Com_rollback%'; //執行回滾的操作
mysql> show global status like '%Bytes_received%'; //接收的字節數
mysql> show global status like '%Bytes_sent%'; //發送的字節數
mysql> show global status like '%com_commit%'; //提交的事務數量,可以用來統計TPS,計算公式:Com_commit/S+Com_rollback/S
mysql> show global status like '%com_begin%'; //開啟的事務數
mysql>show processlist //查看全部的線程,關注time列參數,分析用戶進程占用mysql連接數時長;
mysql>show variables like '%slow%'; //慢查詢
mysql> show variables like "long%"; //慢查詢
mysql> show global status like 'key_read%'; //請求在內存中沒有找到,直接從硬盤讀取索引,計算索引未命中緩存;
mysql> show global status like 'key_read_requests'; //表示總共的索引請求數
mysql> show global status like 'thread%'; //線程緩存查詢
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_cached | 4 | //緩沖池線程個數
| Threads_connected | 6 | //連接中的線程個數
| Threads_created | 97 | //已經創建的線程個數
| Threads_running | 1 |
+-------------------+-------+
4 rows in set (0.00 sec)
mysql> show status like 'threads_cached'; //查看線程緩存內的線程的數量
mysql> show status;
mysql> show status like '%Aborted_clients%'; //由於客戶沒有正確關閉連接已經死掉,已經放棄的連接數量;
mysql> show status like '%Aborted_connects%'; //嘗試已經失敗的Mydql服務器連接次數;
mysql> show status like '%connections%'; //試圖連接mysql的次數
+-----------------------------------+---------------------+
| Variable_name | Value |
+-----------------------------------+---------------------+
| Connection_errors_max_connections | 0 |
| Connections | 27962 |
| Max_used_connections | 13 |
| Max_used_connections_time | 2018-06-26 11:28:15 |
+-----------------------------------+---------------------+
mysql>show status like '%delayed_insert_threads%';//正在使用延遲插入處理器線程的數量;
mysql> show status like '%Delayed_errors%'; //寫入發生錯誤的行數;
mysql> show status like '%open_table%'; //打開表的數量
mysql> show global status like "%opened__tables%"; //曾經打開表的數量
mysql> show status like '%open_file%'; //打開文件的數量
mysql> show status like '%questions%'; //查詢表的數量
mysql> show status like '%threads_connected%'; //打開鏈接的數量
mysql> show status like '%threads_running%'; //不在睡眠的線程的數量
mysql> show status like '%uptime%'; //服務器工作了多少秒
mysql>show status like '%lock%'; //死鎖信息
mysql> show status like '%table%'; //表級鎖
| Table_locks_waited | 0 |
mysql> show global status like 'innodb_row_lock%'; //查看鎖的具體值
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| Innodb_row_lock_current_waits | 0 | //當前正在等待鎖定的數量;
| Innodb_row_lock_time | 51825 | //從系統啟動到現在鎖定總時間長度;
| Innodb_row_lock_time_avg | 2159 | //每次等待所花平均時間
| Innodb_row_lock_time_max | 15858 | //從系統啟動到現在等待最常的一次所花的時間;
| Innodb_row_lock_waits | 24 | //系統啟動后到現在總共等待的次數;
+-------------------------------+-------+
5 rows in set (0.00 sec)
mysql> show global status like 'tabl%'; //全局表鎖
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| Table_locks_immediate | 156 |
| Table_locks_waited | 0 | //的值比較高,則說明存在着較嚴重的表級鎖爭用情況。
| Table_open_cache_hits | 12991901 | //表示立即釋放表鎖數
| Table_open_cache_misses | 4153 |
| Table_open_cache_overflows | 2035 |
+----------------------------+----------+
5 rows in set (0.00 sec)
show status like 'com_select'; //查看本次MySQL啟動后執行的select語句的次數
show global status like 'com_insert'; //查看本次MySQL啟動后執行insert語句的次數
//查詢緩存
mysql> show global status like 'qcache%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 1031832 |
| Qcache_hits | 0 |
| Qcache_inserts | 0 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 10400979 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 1 |
+-------------------------+----------+
8 rows in set (0.00 sec)
Qcache_free_blocks表示緩存中相鄰內存塊的個數,數目越大可能有碎片,flush query cache會對緩存中的碎片進行整理。
Qcache_free_memory 表示緩存中空閑內存
Qcache_hits命中查詢緩存的次數
Qcache_inserts插入一個查詢到緩存的次數,命中次數除以插入次數就是不中比率。
Qcache_lowmem_prunes:緩存出現內存不足並且必須要進行清理以便為更多查詢提供空間的次數。這個數字最好長時間來看;如果這個數字在不斷增長,就表示可能碎片非常嚴重,或者內存很少。(上面的 free_blocks和free_memory可以告訴您屬於哪種情況)
Qcache_not_cached:不適合進行緩存的查詢的數量,通常是由於這些查詢不是 SELECT 語句或者用了now()之類的函數。
Qcache_queries_in_cache:當前緩存的查詢(和響應)的數量。
Qcache_total_blocks:緩存中塊的數量。
mysql> show variables like 'query_cache%'; //query_cache配置
+------------------------------+---------+
| Variable_name | Value |
+------------------------------+---------+
| query_cache_limit | 1048576 | //超過此大小的查詢將不緩存
| query_cache_min_res_unit | 4096 | //緩存塊的最小大小
| query_cache_size | 1048576 | //查詢緩存大小
| query_cache_type | OFF | //緩存類型
| query_cache_wlock_invalidate | OFF | //當有其他客戶端正在對MyISAM表進行寫操作時,如果查詢在query cache中,是否返回cache結果還是等寫操作完成再讀表獲取結果。
+------------------------------+---------+
5 rows in set (0.00 sec)
查詢緩存碎片率 = Qcache_free_blocks / Qcache_total_blocks * 100%
如果查詢緩存碎片率超過20%,可以用FLUSH QUERY CACHE整理緩存碎片,或者試試減小query_cache_min_res_unit,如果你的查詢都是小數據量的話。
查詢緩存利用率 = (query_cache_size – Qcache_free_memory) / query_cache_size * 100%
查詢緩存利用率在25%以下的話說明query_cache_size設置的過大,可適當減小;查詢緩存利用率在80%以上而且Qcache_lowmem_prunes > 50的話說明query_cache_size可能有點小,要不就是碎片太多。
查詢緩存命中率 = (Qcache_hits – Qcache_inserts) / Qcache_hits * 100%
示例服務器 查詢緩存碎片率 = 20.46%,查詢緩存
