-- 生成报告文件到/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 size的大小设置
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;

MySQL性能指标计算方式的更多相关文章

  1. mysql中TPS, QPS 的计算方式

    今天突然有个同事问题一个问题, mysqlTPS和QPS的计算公式是什么? 以前确实也没有关注过这个计算公式,所以查了下学习了下: 下面是参考内容.  在做db基准测试的时候,qps,tps 是衡量数 ...

  2. 【MySQL】计算 TPS,QPS 的方式

     在做db基准测试的时候,qps,tps 是衡量数据库性能的关键指标.本文比较了网上的两种计算方式.先来了解一下相关概念. 概念介绍: QPS:Queries Per Second         查 ...

  3. MySQL的性能指标计算和优化方法

    MySQL的性能指标计算和优化方法1 QPS计算(每秒查询数) 针对MyISAM引擎为主的DB mysql> show global status like 'questions';+----- ...

  4. MySQL性能指标及计算方法

    绝大多数MySQL性能指标可以通过以下两种方式获取: (1)mysqladmin 使用mysqladmin extended-status命令获得的MySQL的性能指标,默认为累计值.如果想了解当前状 ...

  5. MySQL性能指标及计算方法(go)

    绝大多数MySQL性能指标可以通过以下两种方式获取: (1)mysqladmin 使用mysqladmin extended-status命令获得的MySQL的性能指标,默认为累计值.如果想了解当前状 ...

  6. MySQL DDL执行方式-Online DDL介绍

    1 引言 大家好,今天与大家一起分享一下 mysql DDL执行方式. 一般来说MySQL分为DDL(定义)和DML(操作). DDL:Data Definition Language,即数据定义语言 ...

  7. Linux 平台MySQL启动关闭方式总结

    MySQL的启动方法有很多种,下面对比.总结这几种方法的一些差异和特性,下面实验的版本为MySQL 5.6.如有疏漏或不足,敬请指点一二.   1:使用mysqld启动.关闭MySQL服务 mysql ...

  8. System.currentTimeMillis()计算方式与时间的单位转换

    目录[-] 一.时间的单位转换 二.System.currentTimeMillis()计算方式 一.时间的单位转换 1秒=1000毫秒(ms) 1毫秒=1/1,000秒(s)1秒=1,000,000 ...

  9. MySQL 简洁连接数据库方式

    OS  :   CentOS 6.3 DB  :  5.5.14 MySQL连接数据库的方式很多: 1.[root@db01 bin]# ./mysql -uroot -p 2.[root@db01 ...

随机推荐

  1. 通过Fiddler进行手机抓包

    通过Fiddler进行手机抓包 通过Fiddler抓包工具,可以抓取手机的网络通信,但前提是手机和电脑处于同一局域网内(WI-FI或热点),然后进行以下设置: 用Fiddler对Android应用进行 ...

  2. LeetCode——Increasing Triplet Subsequence

    Question Given an unsorted array return whether an increasing subsequence of length 3 exists or not ...

  3. 【医学图像】3D Deep Leaky Noisy-or Network 论文阅读(转)

    文章来源:https://blog.csdn.net/u013058162/article/details/80470426 3D Deep Leaky Noisy-or Network 论文阅读 原 ...

  4. 【Semantic segmentation Overview】一文概览主要语义分割网络(转)

    文章来源:https://www.tinymind.cn/articles/410 本文来自 CSDN 网站,译者蓝三金 图像的语义分割是将输入图像中的每个像素分配一个语义类别,以得到像素化的密集分类 ...

  5. Python学习札记(五) Basic2 字符串和编码

    参考:字符串和编码 Note A.字符编码 1.计算机处理文本 == 将文本转换为二进制 => 处理 2.8 bit(比特) = 1 byte(字节) 一个字节所能表示的最大的十进制整数是255 ...

  6. RabbitMQ 与 AMQP路由

    概述 RabbitMQ(MQ 为 MessageQueue) 是一个消息队列,主要是用来实现应用程序的异步和解耦,同时起到消息缓冲.消息分发作用 消息队列 消息(Message)是指应用间传送的数据, ...

  7. 【Python】关于使用pycharm遇到只能使用unittest方式运行,无法直接选择Run

    相信大家可能都遇到过这个问题,使用pycharm直接运行脚本的时候,只能选择unittest的方式,能愁死个人

  8. 理解JAVA MQ消息中间件

    MQ的几种消息传递方式 发布订阅模式 发布订阅模式有点类似于我们日常生活中订阅报纸.每年到年尾的时候,邮局就会发一本报纸集合让我们来选择订阅哪一个.在这个表里头列了所有出版发行的报纸,那么对于我们每一 ...

  9. React 16.3.0 发布,构建用户界面的 JavaScript 库

    React 16.3.0 已发布,React 是 Facebook 推出的一个为数据提供渲染为 HTML 视图,用来构建用户界面的开源 JavaScript 库. React 视图通常采用包含以自定义 ...

  10. 页面title加icon

    把favicon.ico放入根目录下,在head中添加一下代码 <link rel="icon" type="image/x-icon" href=&qu ...