mysql-copy to tmp table

今天数据后台数据反映有些迟缓后查看链接 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的值作为最大的内存临时表的上限,大于这个时,改写硬盘。

原文blog:http://www.jb51.net/article/19384.htm

时间: 2024-10-24 14:12:07

mysql-copy to tmp table的相关文章

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

mysql copy表或表数据常用的语句整理汇总. 假如我们有以下这样一个表: id username password ----------------------------------- 1 admin ************* 2 sameer ************* 3 stewart ************* #SQL CREATE TABLE IF NOT EXISTS `admin` ( `id` int(6) unsigned NOT NULL auto_increme

MYSQL导入数据:Table XXX doesn't exist的解决

数据表为Innodb引擎 data文件夹中存在数据表的frm文件,但在phpmyadmin中看不到这些表,于是采用导入sql文件的方式进行恢复 1.直接导入原数据表的sql文件,原frm文件不删除 出错:#1146 - Table 'eticket.et_admin' doesn't exist 2.删除原frm文件,刷新phpmyadmin,再导入该数据表的sql文件 出错:#1146 - Table 'eticket.et_admin' doesn't exist 3.删除原frm文件,重启

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

转自:http://ctripmysqldba.iteye.com/blog/1938150 (有修改) MySQL在进行alter table等DDL操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的操作停滞在Waiting for table metadata lock的状态,后续对TableA的任何操作(包括读)都无法进行,因为他们也会在Opening tables的阶段进入到Waiting for

detecting locked tables mysql (locked by LOCK TABLE)

detecting locked tables mysql (locked by LOCK TABLE) up vote15down votefavorite 7 I would like to know whether there is an option to detect locked tables in mysql or not. I mean locked by LOCK TABLE table WRITE/READ command? mysql locking share|impro

A MySQL foreign keys drop table, re-create table example

Summary: How to drop MySQL database tables and recreate them when you have foreign keyrelationships between the tables. This is pretty obscure, but I thought I'd post it here so I wouldn't forget how to do this ... if you ever have a situation when u

MySQL出现Waiting for table metadata lock的原因以及解决方法(转)

MySQL在进行alter table等DDL操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的操作停滞在Waiting for table metadata lock的状态,后续对TableA的任何操作(包括读)都无法进行,因为他们也会在Opening tables的阶段进入到Waiting for table metadata lock的锁等待队列.如果是产品环境的核心表出现了这样的锁等待队列,就会造成

mysql报【unknown table in mulit delete】错的原因和解决办法

今天写一个多表连接删除的DELETE语句,在执行的时候发现报错:unknown table in mulit delete,这里记录下原因. 原来报错的DELETE语句: delete sys_project from sys_project as aa left join ( select min(id) as id from sys_project group by sysCode ) as bb on aa.id = bb.id where bb.id is null 要注意的是,这样的语

一条sql语句引发mysql不停创建临时表的问题解决..coping to tmp table on desk

(不懂临时表的先看 MySQL临时表 ) 首先,临时表只在当前连接可见,当关闭连接时,Mysql会自动删除表并释放所有空间.因此在不同的连接中可以创建同名的临时表,并且操作属于本连接的临时表. 创建临时表的语法与创建表语法类似,不同之处是增加关键字TEMPORARY 临时表主要用于对大数据量的表上作一个子集,提高查询效率.但是当语句写得有问题则可能会造成不断的创建的临时表,导致磁盘I/O利用率过高. 我之前写了一个存储过程,里面有一条语句,刚开始用了group by ..having,如下 用e

mysql copy复制拷贝表数据及结构的几种方式(转)

mysql拷贝表操作我们会常常用到,下面就为您详细介绍几种mysql拷贝表的方式,希望对您学习mysql拷贝表方面能够有所帮助.假如我们有以下这样一个表:id username password-----------------------------------1 admin *************2 sameer *************3 stewart *************CREATE TABLE IF NOT EXISTS `admin` ( `id` int(6) uns