(1) QPS(每秒Query量)
QPS = Questions(or Queries) / uptime
mysql> show global status like 'Question%';
mysql> show global status like 'uptime';
(2) TPS(每秒事務量)
TPS = (Com_commit + Com_rollback) / uptime
mysql > show global status like 'Com_commit';
mysql > show global status like 'Com_rollback';
mysql> show global status like 'uptime';
(3)key Buffer 命中率
mysql>show global status like 'key%';
key_buffer_read_hits = (1-key_reads /key_read_requests) * 100%
key_buffer_write_hits = (1-key_writes /key_write_requests) * 100%
(4)InnoDB Buffer命中率
mysql> show status like 'innodb_buffer_pool_read%';
innodb_buffer_read_hits = (1 -innodb_buffer_pool_reads / innodb_buffer_pool_read_requests) * 100%
(5)Query Cache命中率
mysql> show status like 'Qcache%';
Query_cache_hits = (Qcahce_hits /(Qcache_hits + Qcache_inserts )) * 100%;
(6)Table Cache狀態量
mysql> show global status like 'open%';
比較 open_tables 與opend_tables值
(7)Thread Cache 命中率
mysql> show global status like'Thread%';
mysql> show global status like'Connections';
Thread_cache_hits = (1 - Threads_created /connections ) * 100%
(8)鎖定狀態
mysql> show global status like '%lock%';
Table_locks_waited/Table_locks_immediate=0.3% 若是這個比值比較大的話,說明表鎖形成的阻塞比較嚴重
Innodb_row_lock_waits innodb行鎖,太大多是間隙鎖形成的
(9)複製延時量
mysql > show slave status
查看Seconds_Behind_Master的值,若是爲0,說明沒有延遲
(10) Tmp Table 情況(臨時表情況)
mysql > show global status like 'Created_tmp%';
Created_tmp_disk_tables/Created_tmp_tables比值最好不要超過10%,若是Created_tmp_tables值比較大,
多是排序句子過多或者是鏈接句子不夠優化
(11) Binlog Cache 使用情況
mysql > show global status like 'Binlog_cache%';
若是Binlog_cache_disk_use值不爲0 ,可能須要調大 binlog_cache_size大小
(12) Innodb_log_waits 量
mysql > show status like'innodb_log_waits';
Innodb_log_waits值不等於0的話,代表 innodblog buffer 由於空間不足而等待
(13)open file and table
mysql> show global status like 'Open_files';
mysql> show global status like 'Open_tables';
(14) 慢查詢
開啓慢查詢:
1).手動執行命令開啓:
mysql> set global slow_query_log=on;
mysql> set global long_query_time=1;
2).編輯/etc/my.cnf,在[mysqld]域中添加:
slow_query_log= 1 # 開啓慢查詢
slow_query_log_file=/data/data/localhost-slow.log # 慢查詢日誌路徑
long_query_time= 1 # 慢查詢的時長
(15)全日誌
查看全日誌:
show global variables like 'general_log';
開啓全日誌:
set global general_log=on;
注意開啓全日誌會消耗服務器性能,通常只有在排查問題時纔會短暫打開。mysql
來自 「 ITPUB博客 」 ,連接:http://blog.itpub.net/15498/viewspace-2143928/,如需轉載,請註明出處,不然將追究法律責任。sql