show [global | session] status [like 'xxx'];

global选项,查看mysql所有连接状态

session选项,查看当前连接状态,默认session选项

flush status;可以将很多状态值重置清零。

获取mysql用户进程总数

ps -ef |awk '{print $1}' |grep mysql |grep -v "grep" |wc -l

查看mysql当前连接数

netstat -an |grep 3306 |grep "ESTABLISHED" |wc -l

查看主机性能状态

uptime

 11:03:30 up 91 days,  9:48,  3 users,  load average: 0.70, 0.91, 2.63

查看服务器启动时长,用户数,负载

top  vmstat,top   查看cpu使用率

vmstat  iostat  查看io状态

free -h  查看内存使用情况

数据库性能状态查询:

1)QPS每秒query量

show global status like 'Question%';

+---------------+----------+

| Variable_name | Value    |

+---------------+----------+

| Questions     | 39661402 |

+---------------+----------+

2)TPS每秒事务量

show global status like 'Com_commit';

+---------------+---------+

| Variable_name | Value   |

+---------------+---------+

| Com_commit    | 8495153 |

+---------------+---------+

show global status like 'Com_rollback';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| Com_rollback  | 0     |

+---------------+-------+

(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的话,表明 innodb log  buffer 因为空间不足而等待

13)show variables like '%timeout%';查看连接超时配置