【问题标题】:How to list cached queries in MySQL? (Qcache_queries_in_cache)如何在 MySQL 中列出缓存的查询? (Qcache_queries_in_cache)
【发布时间】:2011-05-10 10:09:17
【问题描述】:

显示类似“Qcache_queries_in_cache”返回的状态:

+-------------------------+----------+
| Variable_name           | Value    |
+-------------------------+----------+
| Qcache_queries_in_cache | 327      |
+-------------------------+----------+

如何打印这 327 个查询?

为了优化 mysql 缓存,我想尝试切换到“按需”缓存。但在此之前,我想明确了解哪些查询被缓存或丢弃。我尝试了 mysql docs、google 和 stackoverflow 搜索,但没有成功。

【问题讨论】:

    标签: sql database caching mysql


    【解决方案1】:

    AFAIK sql 查询不存储到 Qcache 中,只存储它们的哈希值。因此,除了您执行其中一个查询并查看 Value 列的更改之外,无法找到现在缓存了哪些查询。

    【讨论】:

    • thx...我在生产服务器上执行许多查询并发现更改将不起作用。我希望有某种调试模式。
    • 有没有办法获得这些哈希值?
    【解决方案2】:

    如果您启用会话特定变量分析

    SET SESSION PROFILING=on;
    show profiles;
    

    现在通过检查显示配置文件来查询您的 query_id;

    mysql> show profile for query 2;
    
    +--------------------------------+----------+
    | Status                         | Duration |
    +--------------------------------+----------+
    | starting                       | 0.000017 |
    | checking query cache for query | 0.000005 |
    | checking privileges on cached  | 0.000003 |
    | sending cached result to clien | 0.000005 |
    | logging slow query             | 0.000002 |
    | cleaning up                    | 0.000001 |
    +--------------------------------+----------+
    

    通过检查状态列,您可以查看查询是否被缓存。

    但这只是您为每个会话启用分析的特定会话。

    【讨论】:

      猜你喜欢
      • 2013-06-28
      • 2011-06-01
      • 2010-09-07
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      • 2014-06-25
      • 2016-09-14
      • 1970-01-01
      相关资源
      最近更新 更多