MYSQL常用的性能指標


(1) QPS(每秒Query量)

QPS = Questions(or Queries) / seconds

mysql > show  global status like 'Question%';

 

(2) TPS(每秒事務量)

TPS = (Com_commit + Com_rollback) / seconds

mysql > show global status like'Com_commit';

mysql > show global status like'Com_rollback';

 

(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

查看延時時間

 

(10) Tmp Table 狀況(臨時表狀況)

mysql > show status like 'Create_tmp%';

Created_tmp_disk_tables/Created_tmp_tables比值最好不要超過10%,如果Created_tmp_tables值比較大,

可能是排序句子過多或者是連接句子不夠優化

 

(11) Binlog Cache 使用狀況

mysql > show 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> mysql -e "show global statuslike 'Open_files';

mysql> mysql -e "show global statuslike 'Open_tables';

 

(14) 慢查詢

開啟慢查詢:

         編輯/etc/my.cnf,在[mysqld]域中添加:

         slow_query_log= 1   # 開啟慢查詢

         slow_query_log_file=/data/mysql/slow.log   # 慢查詢日志路徑

         long_query_time= 1        # 慢查詢的時長

查看慢查詢數量:

         執行mysqladminstatus

 

(15)全日志

查看全日志:

  show global variables like 'general_log';

開啟全日志:

    set global general_log=on;

注意開啟全日志會消耗服務器性能,一般只有在排查問題時才會短暫打開。

 

########### 分割線 ###########

我們需要根據自己的情況進行配置優化,好的做法是MySQL服務器穩定運行了一段時間后,根據服務器的”狀態”再進行優化。


免責聲明!

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



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