mysql一直copying to tmp table_Mysql慢查询之Copying to tmp table

2ff34e647e2e3cdfd8dca593e17d9b0a.png

问题:网站出现卡的情况,观察堆栈发现很多Copying to tmp table这种状态耗时较长

​ 产生原因: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的限制,那么用/tmp保存查询结果,tmp_table不得不拷到硬盘上,然后返回给客户端)

​ 解决方案:放大tmp_table_size

​ 1)查询tmp_table_size 为默认16M

​ mysql> show variables like ‘%tmp%’;

​ +——————-+———-+

​ | Variable_name | Value |

​ +——————-+———-+

​ | max_tmp_tables | 32 |

​ | slave_load_tmpdir | /tmp |

​ | tmp_table_size | 16777216 |

​ | tmpdir | /tmp |

​ +——————-+———-+

​ 4 rows in set (0.00 sec)

​ /etc/my.cnf添加

​ tmp_table_size = 256M

​ 2)优化sql

​ 3)拓展-其他常用参数

​ mysql> show global status like ‘qcache%‘;

​ 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会被装载到内存。那样会增加数据库访问速度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值