设为首页 收藏本站
查看: 853|回复: 0

[经验分享] MySQL性能指标计算方式

[复制链接]

尚未签到

发表于 2018-10-10 11:40:20 | 显示全部楼层 |阅读模式
  -- 生成报告文件到/tmp目录中
  tee /tmp/mysql_performance_stat.txt
  -- 统计性能指标前先开启下列参数,该参数使用IS数据库来存放数据库信息,由于使用PS库存放还存在BUG,信息统计不全
  show variables like 'show_compatibility_56';
  set global show_compatibility_56=on;
  show variables like 'show_compatibility_56';
  -- QPS 计算(针对MyISAM引擎为主)
  select variable_value into @v_questions from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Questions';
  select variable_value into @v_uptime from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Uptime';
  select round(@v_questions/@v_uptime,3) as "MyISAM/QPS";
  -- QPS 计算(针对InnoDB引擎为主)
  select variable_value into @v_com_update from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Com_update';
  select variable_value into @v_com_select from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Com_select';
  select variable_value into @v_com_insert from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Com_insert';
  select variable_value into @v_com_delete from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Com_delete';
  select variable_value into @v_uptime from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Uptime';
  select round((@v_com_update+@v_com_select+@v_com_insert+@v_com_delete)/@v_uptime,3) as "InnoDB/QPS";
  -- TPS 计算 (每秒事务数)
  select variable_value into @v_com_commit from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Com_commit';
  select variable_value into @v_com_rollback from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Com_rollback';
  select variable_value into @v_uptime from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Uptime';
  select round((@v_com_commit+@v_com_rollback)/@v_uptime,3) as "InnoDB/TPS (每秒事务数)";
  -- InnoDB 缓存命中率
  select variable_value into @v_read_requests from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Innodb_buffer_pool_read_requests';
  select variable_value into @v_read_ahead from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Innodb_buffer_pool_read_ahead';
  select variable_value into @v_reads from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Innodb_buffer_pool_reads';
  select concat(round(@v_read_requests/(@v_read_requests+@v_read_ahead+@v_reads)*100,3),"%") as "InnoDB 缓存命中率";
  -- Thread Cache命中率
  select variable_value into @v_threads_created from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Threads_created';
  select variable_value into @v_connections from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Connections';
  select concat(round((1-@v_threads_created/@v_connections)*100,3),"%") as "线程缓存命中率";
  -- 临时表使用情况
  select variable_value into @v_Created_tmp_disk_tables from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Created_tmp_disk_tables';
  select variable_value into @v_Created_tmp_files from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Created_tmp_files';
  select variable_value into @v_Created_tmp_tables from INFORMATION_SCHEMA.global_status t1 where t1.variable_name='Created_tmp_tables';
  select variable_value/1024/1024 into @v_tmp_table_size from INFORMATION_SCHEMA.GLOBAL_VARIABLES where VARIABLE_NAME='tmp_table_size';
  select @v_tmp_table_size as "tmp_table_size(M)",@v_Created_tmp_disk_tables as Created_tmp_disk_tables,@v_Created_tmp_tables as Created_tmp_tables,@v_Created_tmp_files as Created_tmp_files,concat(round(@v_Created_tmp_disk_tables/@v_Created_tmp_tables*100,3),"%") as "临时表磁盘使用率";
  -- 连接比率
  select VARIABLE_VALUE into @v_max_conn from  INFORMATION_SCHEMA.GLOBAL_VARIABLES where VARIABLE_NAME='max_connections';
  select VARIABLE_VALUE into @v_top_con from  INFORMATION_SCHEMA.GLOBAL_STATUS where VARIABLE_NAME='Max_used_connections';
  select count(*) into @v_current_con from performance_schema.threads where type = 'FOREGROUND';
  select @v_current_con as "当前连接数",@v_max_conn as "最大连接数",@v_top_con as "连接数最大峰值";

  -- Innodb log buffer>  select VARIABLE_VALUE/1024/1024 into @v_innodb_log_buffer_size from  INFORMATION_SCHEMA.GLOBAL_VARIABLES where VARIABLE_NAME='innodb_log_buffer_size';
  select VARIABLE_VALUE into @Innodb_log_waits from  INFORMATION_SCHEMA.GLOBAL_STATUS where VARIABLE_NAME='Innodb_log_waits';
  select @v_innodb_log_buffer_size as "日志缓存区大小(M)",@Innodb_log_waits as Innodb_log_waits;
  -- 统计存储引擎分布情况
  SELECT COUNT(*), engine FROM information_schema.TABLES WHERE table_schema NOT IN ('information_schema' , 'performance_schema', 'sys', 'mysql') GROUP BY engine;
  SELECT COUNT(*),table_schema,engine FROM information_schema.TABLES WHERE table_schema NOT IN ('information_schema' , 'performance_schema', 'sys', 'mysql') GROUP BY table_schema,engine;


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-619920-1-1.html 上篇帖子: mysql编译脚本 下篇帖子: mysql5.5 5.6 5.7新特性
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表