AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 57418
Accepted
AJB
AJB
Asked: 2014-01-24 12:23:06 +0800 CST2014-01-24 12:23:06 +0800 CST 2014-01-24 12:23:06 +0800 CST

如何确定每天的 MySQL 查询量?

  • 772

我正在调查从 MySQL 到 NoSQL DBaaS 的重大转变,并且在尝试预测费用时遇到了问题。从本质上讲,我无法弄清楚我当前的 MySQL 服务器每天处理多少查询来尝试估计我将与Cloudant一起使用的请求数量,每 100 次 PUT、POST 和 DELETE 收费 0.015 美元,每 500 次 GET 收费 0.015 美元和头。

我发现了很多关于使用SHOW STATUS和SHOW GLOBAL STATUS来获取 MySQL 自己收集的统计信息的信息,但是没有时间框架参考。

例如, SHOW GLOBAL STATUS 返回以下内容:

Queries                           | 13576675

这很好,除了我不知道包含该数字的时间范围。1300 万次查询是什么时候?每月?年?自古以来?

MySQL 文档并没有真正详细说明:

查询

服务器执行的语句数。与 Questions 变量不同,此变量包括在存储程序中执行的语句。它不计算 COM_PING 或 COM_STATISTICS 命令。这个变量是在 MySQL 5.0.76 中添加的。

提前感谢您的帮助。

mysql
  • 2 2 个回答
  • 21152 Views

2 个回答

  • Voted
  1. Best Answer
    Maxime Fouilleul
    2014-01-24T12:43:10+08:002014-01-24T12:43:10+08:00

    对于选择:

    show global status like "Com_select";
    

    更新:

    show global status like "Com_update";
    

    插入:

    show global status like "Com_insert";
    

    删除:

    show global status like "Com_delete";
    

    自 MySQL 上次重新启动以来,所有值都是“累积的”。

    所以要在一小时内得到你的选择:

    晚上 9 点:

    [21:00:00] [DEV\(none)] mysql> show global status like "Com_select";
    +---------------+--------+
    | Variable_name | Value  |
    +---------------+--------+
    | Com_select    | 671664 |
    +---------------+--------+
    1 row in set (0.00 sec)
    

    晚上 10 点:

    [22:00:00] [DEV\(none)] mysql> show global status like "Com_select";
    +---------------+--------+
    | Variable_name | Value  |
    +---------------+--------+
    | Com_select    | 672363 |
    +---------------+--------+
    1 row in set (0.00 sec)
    

    过去一小时的 SELECT 次数:672363 - 671664 = 699

    此致

    • 23
  2. Matty
    2017-04-21T14:26:39+08:002017-04-21T14:26:39+08:00

    我使用这个视图来关注每秒、每分钟、每小时和每天的查询数量:

    create or replace view _dba_query_stats as
    select 
      SUBSTRING(VARIABLE_NAME, 5) as query_type, 
      VARIABLE_VALUE as total_count, 
      round(VARIABLE_VALUE / ( select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status'), 2) as per_second,
      round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60)))       as per_minute,
      round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60*60)))    as per_hour, 
      round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60*60*24))) as per_day,
      FROM_UNIXTIME(round(UNIX_TIMESTAMP(sysdate()) - (select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status'))) report_period_start,
      sysdate() as report_period_end,
      TIME_FORMAT(SEC_TO_TIME((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status')),'%Hh %im') as report_period_duration
    from 
      information_schema.GLOBAL_STATUS 
    where 
      VARIABLE_NAME in ('Com_select', 'Com_delete', 'Com_update', 'Com_insert');
    

    样本输出:

    query_type total_count per_second per_minute per_hour per_day report_period_start report_period_end   report_period_duration
    DELETE               0          0          0       0        0 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
    INSERT           36595       0.09          5     320     7672 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
    SELECT        14842019      36.02       2161  129656  3111738 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
    UPDATE          189137       0.46         28    1652    39654 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
    
    • 14

相关问题

  • 是否有任何 MySQL 基准测试工具?[关闭]

  • 我在哪里可以找到mysql慢日志?

  • 如何优化大型数据库的 mysqldump?

  • 什么时候是使用 MariaDB 而不是 MySQL 的合适时机,为什么?

  • 组如何跟踪数据库架构更改?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve