数据库监控的指标
1,慢查询
show variables like '%slow%'
show global status like '%long_query%'
具体配置见文档
mysqldumpslow -s at 10 slow.log
2,连接数
show variables like '%connections%'
show status like '%thread%'
其中:
Threads_connected 当前打开的连接的数量
Threads_cached 线程缓存内的线程的数量
Threads_created 创建的线程数
Threads_running 激活的(非睡眠状态)线程数
show status like '%connection%'
Connections 试图连接MySQL服务器的次数
3,缓冲池
show variables like '%buffer_pool_size%'
show status like '%buffer%';
其中:
Innodb_buffer_pool_reads:缓冲池中没有读到数据,而从磁盘内读取的次数
Innodb_buffer_pool_read_requests:来缓冲池中读数据的次数
Innodb_buffer_pool_pages_total:缓冲池的总页数(内存是以页为单位)
Innodb_buffer_pool_pages_free:缓冲池中处于空闲状态的页数
命中率:innodb_buffer_read_hits=(1-Innodb_buffer_pool_reads/Innodb_buffer_pool_read_requests)*100%
4,查询缓存 -- 了解
show variables like '%query_cache%';
show status like '%Qcache%'
Query_cache_hits=(Qcache_hits/(Qcache_hits+Qcache_inserts))*100%
5,线程缓存(连接池)-- 了解
show variables like '%thread%'
show status like 'connections'
show status like '%thread%'
Threads_Cache_Hit=(Connections-Threads_created)/Connections*100%
6,表锁和行锁 -- 了解
show status like '%lock%';
存储引擎:早期mysql用的,MyISAM,现在都用Innodb
MyISAM:支持表锁
Innodb:支持行锁、支持事务
【常用语句】
-- 查看是否开启慢查询日志
show variables like 'slow_query%';
-- 开启慢查询日志
set global slow_query_log=1;
-- 查看慢查询的指标
show variables like 'long_query_time';
-- 设置慢查询的指标(秒)
set global long_query_time=2;
-- 设置慢查询日志文件位置
set global slow_query_log_file='d:\mysql\slow_query.log';
-- 查询慢查询日志形式
select @@global.log_output
-- 设置慢查询日志为表,就可以在mysql.slow_log表中查看相关参数
set @@global.log_output='TABLE';
【slow_sql主要参数】
Query_time:查询时长(秒)
Lock_time:锁持有时长(秒)
Rows_sent:返回客户端的行数
Rows_examined:优化器扫描行数,这个要尽量减少
创作不易,转摘请标明出处。如果有意一起探讨测试相关技能可加博主QQ 771268289 博主微信:ding17121598
本文来自博客园,作者:怪圣卡杰,转载请注明原文链接:https://www.cnblogs.com/dwdw/p/10897469.html