MYSQL服务器状态

Posted zghw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL服务器状态相关的知识,希望对你有一定的参考价值。

#系统变量
show variables ;
#会话变量只读
show status ;
#全局变量
show global status;


######线程和链接统计#######
show status where variable_name='Connections' or variable_name='Max_used_connections' or variable_name='Threads_connected'
or variable_name='Aborted_clients' or variable_name='Bytes_received' or variable_name='Bytes_sent' or variable_name='Slow_launch_threads'
or variable_name='Threads_cached'or variable_name='Threads_created' or variable_name='Threads_running'; 
#全局#试图连接到(不管是否成功)mysql服务器的 连接数
show status where variable_name='Connections'; 
#全局#服务器启动后已经同时使用的连接的最大数量。
show status where variable_name='Max_used_connections';
#全局#当前打开的链接数量
show status where variable_name='Threads_connected';
#全局#由于客户端没有正确关闭链接导致客户端终止而中断的连接数.
show status where variable_name='Aborted_clients';
#全局#试图连接到MYSQL服务器而失败的连接数
show status where variable_name='Aborted_connects';
#BOTH#从所有客户端接收到的字节数。
show status where variable_name='Bytes_received';
#BOTH#发送给所有客户端的字节数.
show status where variable_name='Bytes_sent';
#如果创建线程的时间超过该秒数,服务器增加Slow_launch_threads状态变量。
show variables where variable_name='slow_launch_time';
show status where variable_name='Slow_launch_threads';
#全局#线程缓存内的线程数量.
show status where variable_name='Threads_cached';
#global#创建用来处理连接的线程数。如果Threads_created较大,你可能要增加thread_cache_size值。 缓存访问率的计算方法Threads_created/Connections。
show status where variable_name='Threads_created';
#global #激活的(非睡眠状态)线程数。
show status where variable_name='Threads_running';


##############二进制日志状态#############
#在二进制日志中缓存中有多少事务被存储过.
show status where variable_name='Binlog_cache_use';
#多少事务因为超过二进制日志缓存而必须存储到一个临时文件中.
show status where variable_name='Binlog_cache_disk_use';
#事务度量值
show status where variable_name='Binlog_stmt_cache_use';
###############命令计数器#########
show status like 'Com_%';
#全局的增删改查数量,不太准确
show status where variable_name='com_select';
show status where variable_name='com_insert';
show status where variable_name='com_update';
show status where variable_name='com_delete';
#事务统计
show status where variable_name='com_commit';
show status where variable_name='com_rollback';


#使用innodb统计的增删改查
show status like 'Innodb_rows%';


#################临时文件和表################
#隐式临时表和文件的统计--执行查询时内部创建.
show global status like 'Created_tmp%';




################句柄操作################
#句柄API是MYSQL和存储引擎之间的接口. 统计句柄的数量
show global status like 'Handler_%';
#分析这几个值,我们可以查看当前索引的使用情况:
#Handler_read_first:索引中第一条被读的次数。如果较高,它表示服务器正执行大量全索引扫描;例如,SELECT col1 FROM foo,假定col1有索引(这个值越低越好)。
#Handler_read_key:如果索引正在工作,这个值代表一个行被索引值读的次数,如果值越低,表示索引得到的性能改善不高,因为索引不经常使用(这个值越高越好)。
#Handler_read_next :按照键顺序读下一行的请求数。如果你用范围约束或如果执行索引扫描来查询索引列,该值增加。
#Handler_read_prev:按照键顺序读前一行的请求数。该读方法主要用于优化ORDER BY ... DESC。
#Handler_read_rnd :根据固定位置读一行的请求数。如果你正执行大量查询并需要对结果进行排序该值较高。你可能使用了大量需要MySQL扫描整个表的查询或你的连接没有正确使用键。这个值较高,意味着运行效率低,应该建立索引来补救。
#Handler_read_rnd_next:在数据文件中读下一行的请求数。如果你正进行大量的表扫描,该值较高。通常说明你的表索引不正确或写入的查询没有利用索引。


###############MyISAM键缓冲计数#################
show global status like 'Key_%';
#使用MyISAM存储引擎,那么Open_*变量揭示了MySQL每隔多久会打开每个表的.frm .MYI和.MYD文件.
show global status like 'open_%';


############查询缓存##########
show global status like 'Qcache_%';


##############select类型################
#帮助你了解使用各种查询计划的SELECT查询比例.
show global status like 'select_%';
#在第一个表上扫描一个索引区间的联接数目.
show global status where variable_name='select_range';
#扫描整个第一张表的联接数目.如果第一个表中每行都参与联接,这样计数并没有问题.
#如果你不想要所有行但又没有索引以查找到所需要的行,那就糟糕了.
show global status where variable_name='select_scan';
#使用在表n中的一个值来从表n+1中通过参考索引的区间来获取行所做的联接数.
show global status where variable_name='select_full_range_join';
#在表n+1中重新评估表n中的每一行的索引是否开销最小所做的联接数,这一般意味着在表n+1中对该联接而言并没有有用的索引.
#这个查询有非常高的额外开销.
show global status where variable_name='select_range_check';
#交叉联接或并没有条件匹配表中行的联接的数目.检测的行数是每个表中行数的乘积.
show global status where variable_name='select_full_join';


###########排序##########
show global status like 'sort_%';


#########表锁########
#多少锁被立即授权
show status where variable_name='Table_locks_immediate';
#多少锁需要等待
show status where variable_name='table_locks_waited';


#进程列表是当前连接到mysql的链接或线程清单.
show processlist;
show full processlist;


#监测复制,在主库上执行则显示主库的复制状态和配置
show master status;


show binary logs;


#InnoDB相关
show engine innodb status;
show global status like 'Innodb_%';








select * from hello_base t1,hello_base t2 where t1.id = t2.hits and t1.hits/2=0 and t1.name like '%JQ%';


select count(*) from hello_base t1,hello_base t2 where t1.name=t2.hits;




show variables like 'slow_%';
set global slow_launch_time=2;
show variables like '%long_query_time%';
set long_query_time=0;
set profiling =1;
show profiles;
show profile for query 1;

以上是关于MYSQL服务器状态的主要内容,如果未能解决你的问题,请参考以下文章

滑动窗口解乘积小于K的子数组

LeetCode 5849. 好子集的数目(状压dp)

19 01-通过状态掩码读取DTC数目

mysql之状态监控

调整innodb redo log files数目和大小的具体方法和步骤

哈希表题目:数的平方等于两数乘积的方法数