今天数据后台数据反映有些迟缓后查看链接 processlist 发下好多 锁 和磁盘写入,
 
参考文章 : http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3646279
http://www.cnblogs.com/JulyZhang/archive/2011/01/28/1947165.html
 
+-----+--------+-----------+--------------+---------+------+----------------------+---------+
| Id  | User   | Host      | db           | Command | Time | State                | Info                                                                                                |
+-----+--------+-----------+--------------+---------+------+----------------------+---------+
|   7 | echina | localhost | echinacities | Query   |   19 | Locked               | 
|  31 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 408 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 464 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 471 | echina | localhost | echinacities | Query   |   21 | Locked               | 
| 499 | echina | localhost | echinacities | Query   |   22 | Copying to tmp table | 
| 545 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 569 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 588 | echina | localhost | echinacities | Query   |   21 | Locked               | 
| 589 | echina | localhost | echinacities | Query   |   21 | Locked               | 
| 602 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 624 | echina | localhost | echinacities | Query   |   21 | Locked               | 
| 647 | echina | localhost | echinacities | Query   |   19 | Locked               | 
| 651 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 680 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 681 | echina | localhost | echinacities | Query   |   21 | Locked               | 
| 688 | echina | localhost | echinacities | Query   |   17 | Locked               | 
| 704 | echina | localhost | echinacities | Query   |   22 | Locked               | 
| 709 | echina | localhost | echinacities | Query   |   21 | Locked               | 
| 710 | echina | localhost | echinacities | Query   |   20 | Locked               | 
| 711 | echina | localhost | echinacities | Query   |   20 | Locked               | 
| 713 | echina | localhost | echinacities | Query   |   19 | Locked               | 
| 718 | echina | localhost | echinacities | Query   |   12 | Locked               | 
| 720 | echina | localhost | echinacities | Query   |   18 | Locked               | 
| 729 | echina | localhost | echinacities | Query   |   16 | Locked               | 
| 731 | echina | localhost | echinacities | Query   |   15 | Locked               | 
| 745 | echina | localhost | echinacities | Sleep   |   11 |                      | 
| 746 | echina | localhost | echinacities | Query   |   11 | Locked               | 
| 748 | echina | localhost | echinacities | Sleep   |   10 |                      | 
| 749 | echina | localhost | echinacities | Query   |   10 | Locked               | 
+-----+--------+-----------+--------------+---------+------+----------------------+-
 
 
mysql默认
tmp_table_size 33554432 (33.5M)
max_heap_table_size 16777216 (16.7M)
 
copy to tmp table的SQL语句,这条语读的时间比较长,且这个表会被加读锁,相关表的update语句会被排进队列。如果多执行几次这样的copyt to tmp table 语句,会造成更多的语句被阻塞。
连接太多造成mysql处理慢。
copy to tmp talbe 语句产生的原因是查询需要Order By 或者Group By等需要用到结果集时,参数中设置的临时表的大小小于结果集的大小时,就会将该表放在磁盘上,这个时候在硬盘上的IO要比内销差很多。所耗费的时间也多很多。另外Mysql的另外一个参数max_heap_table_size比tmp_table_size小时,则系统会把 max_heap_table_size的值作为最大的内存临时表的上限,大于这个时,改写硬盘。
 

mysql-copy to tmp table的更多相关文章

  1. copy to tmp table

    +-----+--------+-----------+--------------+---------+------+----------------------+---------+ | Id   ...

  2. mysql 查询copy to tmp table造成堵塞

    show full PROCESSLIST; show VARIABLES like 'tmp_table_size' set GLOBAL tmp_table_size=629145600; SHO ...

  3. MySQL 优化 之 Copying to tmp table on disk

    项目中遇到了慢查询问题 Sql语句 SELECT sum(price) AS price, `member_id` FROM `crm_upload` GROUP BY member_id ORDER ...

  4. mysql copy表或表数据常用的语句整理汇总

    mysql copy表或表数据常用的语句整理汇总. 假如我们有以下这样一个表: id username password ----------------------------------- 1 a ...

  5. mysql批量进行optimize table操作

    数据库运行一段时间后,有可能会有磁盘磁片产生,此时我们需要进行optimize table操作 # 获取需要optimize的表:如下为获取总大小小于80G的表进行操作:mysql -utroot - ...

  6. MySQL出现Waiting for table metadata lock的原因以及解决方法

    转自:http://ctripmysqldba.iteye.com/blog/1938150 (有修改) MySQL在进行alter table等DDL操作时,有时会出现Waiting for tab ...

  7. 【转】【MySql】Waiting for table metadata lock原因分析

    MySQL在进行alter table等DDL操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的操作停滞在Wa ...

  8. How to Quickly Create a Copy of a Table using Transact-SQL

    The easiest way to create a copy of a table is to use a Transact-SQL command. Use SELECT INTO to ext ...

  9. detecting locked tables mysql (locked by LOCK TABLE)

    detecting locked tables mysql (locked by LOCK TABLE) up vote15down votefavorite 7 I would like to kn ...

随机推荐

  1. [Java][Liferay] 解决Liferay ext项目deploy的问题

    Liferay ext project在install war包之后需要重启服务器,重启服务器中会执行ExtHotDeployListener中的逻辑,这里有一个坑,如果是第二次以后install e ...

  2. HTTP缓存技术,304和200有何区别

    为什么有的缓存是 200 OK (from cache),有的缓存是 304 Not Modified 呢?很简单,看运维是否移除了 Entity Tag.移除了,就总是 200 OK (from c ...

  3. axios使用配置

    axios 配置 下载cnpm install axios vue-axios --save-dev main.js文件中配置 import axios from 'axios' import Vue ...

  4. mybatis-generator.xml

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...

  5. intelij idea相关笔记--持续更新

    一.快捷键: Ctrl+F 文件内查找 Ctrl+Shift+F 全局查找 Ctrl+Shift+N 查找文件 Ctrl+Alt+← 返回上一步 Ctrl+Alt+→ 返回下一步 二.编译相关: 如果 ...

  6. C#中split的方法汇总

    字符串的处理往往离不开split方法,下面介绍几种split的用法: 1.对单个字符进行分割(注意这里是字符,不是字符串,故只能用单引号‘’) string s=abcdeabcdeabcde; st ...

  7. 新版graylog2安装过程

    Graylog是一个开源的 log 收容器,背后的储存是搭配 mongodb,而搜寻引擎则由 elasticsearch 提供.以前版本主要有两个部分集合而成 server 与 web interfa ...

  8. 在 Visual Studio 或 SQLServer Management Studio 的代码编辑器中使用正则表达式匹配日期格式

    使用正则查找时间格式文本 VS正则: (:z表示数字) ':z-:z-:z :z[\:]:z[\:]:z'

  9. 【BZOJ3209】花神的数论题(数位DP)

    点此看题面 大致题意: 设\(sum(i)\)表示\(i\)二进制中1的个数,请求出\(\prod_{i=1}^n sum(i)\). 数位\(DP\) 很显然,这是一道数位\(DP\)题.我们可以先 ...

  10. 【BZOJ4196】[NOI2015] 软件包管理器(树链剖分)

    点此看题面 大致题意: 有\(n\)个软件包,它们的依赖关系形成一棵树.现在,问你安装或卸载一个软件包,会影响多少个软件包的安装状态. 树链剖分 这道题应该是 树链剖分 算法比较入门的题目吧. 对于安 ...