zoukankan      html  css  js  c++  java
  • "Copying to tmp table" Problem Solving

    今天一早突然系统突然报慢,查了一下是以下语句:

    6177700 username ip db——name Query 549 Copying to tmp table SELECT ....................


    原因如下:
    Copying to tmp table on disk The temporary result set was larger than tmp_table_size and the thread is now changing the in memory-based temporary table to a disk based one to save memory.

    如果查询超出了tmp_table_size的限制,那么mysql用/tmp保存查询结果,然后返回给客户端。
    set global tmp_table_size=209715200 (200M)

    解决方法:
    0. /opt/mysql/bin/mysqladmin processlist -uroot -ppassword --或者
    mysql> set names utf8;
    mysql> show processlist;
    1. kill 6177700 --基本可以解决,如果杀不掉,运行2,彻底点儿
    2. sudo /etc/init.d/mysql restart

    后续:
    1. explain看看select语句索引使用状况:

    explain SELECT .............


    2. 尽量避免用 not in ,in, left join ,right join用 exist ,not exist, minus等代替in ,not in

    3.从网上查到,还要再看看更多参数:
    调节tmp_table_size 的时候发现另外一些参数
    Qcache_queries_in_cache 在缓存中已注册的查询数目
    Qcache_inserts 被加入到缓存中的查询数目
    Qcache_hits 缓存采样数数目
    Qcache_lowmem_prunes 因为缺少内存而被从缓存中删除的查询数目
    Qcache_not_cached 没有被缓存的查询数目 (不能被缓存的,或由于 QUERY_CACHE_TYPE)
    Qcache_free_memory 查询缓存的空闲内存总数
    Qcache_free_blocks 查询缓存中的空闲内存块的数目
    Qcache_total_blocks 查询缓存中的块的总数目

    Qcache_free_memory 可以缓存一些常用的查询,如果是常用的sql会被装载到内存。那样会增加数据库访问速度。

  • 相关阅读:
    python学习之旅-02
    python学习之旅-01
    wps2016热点永久关闭
    一个游戏制作的全过程
    游戏是怎么赚钱的
    游戏数值策划入门教程
    成长系统的设计方法:如何“挖坑”,又不让玩家反感
    游戏数值策划经验篇:从多角度解读游戏经验值设计
    暴雪战斗公式——除法公式的精髓
    游戏数值策划属性篇(二):属性价值评估
  • 原文地址:https://www.cnblogs.com/buro79xxd/p/1682569.html
Copyright © 2011-2022 走看看