Copying to tmp table Problem Solving
Labels: MySQL, MySQL_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會被裝載到內存。那樣會增加數據庫訪問速度。
轉載于:https://www.cnblogs.com/buro79xxd/archive/2009/11/24/1682569.html
總結
以上是生活随笔為你收集整理的Copying to tmp table Problem Solving的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: javascript保留两位
- 下一篇: win10蓝牙开关不见了_来自德国,比J