使用GLOBAL選項,您可以得到所有MySQL連接的狀態值。使用SESSION,您可以得到所有當前連接的狀態值。如果您兩個選項都不使用,則默認值爲SESSION。LOCAL是SESSION的同義詞。
注意,有些狀態變量只有一個全局值。對於這些變量,使用GLOBAL和SESSION會得到同樣的值。
用FLUSH STATUS語句可以將許多狀態變量重設爲0。
一,獲取mysql用戶下的進程總數
ps -ef | awk '{print $1}' | grep "mysql" | grep -v "grep" | wc-1
二,主機性能狀態
# uptime
[root@ ~]# uptime
三,CPU使用率
# top 或
四,磁盤IO量
# vmstat 或 # iostat
五,swap進出量[內存]
# free
六,數據庫性能狀態
(1)QPS(每秒Query量)
QPS = Questions(or Queries) / seconds
mysql > show
(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
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
比較 open_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
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的話,表明 innodb log