http://dba.stackexchange.com/questions/30505/why-does-mysql-produce-so-many-temporary-myd-files

Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

On a Debian Linux server, hosting many PHP/MySQL websites (photo galleries), sometimes I have "many" files like /tmp/#sql_6405_58.MYD.

For example today :

[2012-12-15 15:18:11] /tmp/#sql_6405_6.MYD : 88MB
[2012-12-15 15:18:11] /tmp/#sql_6405_3.MYD : 22MB
[2012-12-15 15:18:11] /tmp/#sql_6405_4.MYD : 138MB
[2012-12-15 15:18:11] /tmp/#sql_6405_10.MYD : 88MB
...
[2012-12-15 15:18:11] /tmp/#sql_6405_9.MYD : 15MB
[2012-12-15 15:18:11] /tmp/#sql_6405_65.MYD : 49MB
[2012-12-15 15:18:11] /tmp/#sql_6405_44.MYD : 69MB

(59 files at the same time, for more than 6GB... yes I monitor big files in /tmp)

Unfortunately, /tmp is on the same partition than / and it temporary breaks the web server, because / is full I suppose. Then files disappear and the server is back to normal.

All the file names follow the #sql_6405_*.MYD pattern. I would like to understand which MySQL operation implies so many temporary files. I have approximately 2000 databases on this server. Is it possible to know which database is concerned?

asked Dec 15 '12 at 20:21
 
plegall

migrated from stackoverflow.com Dec 16 '12 at 2:08

This question came from our site for professional and enthusiast programmers.

 
1  
I'm guessing they're temp data for large operations that use filesort, and 6405 is the PID of mysql to keep temp files from different server instances separate.
– 
Marc B
Dec 15 '12 at 20:27
    
Should I ask an admin to move my question?
– 
plegall
Dec 15 '12 at 22:06

3 Answers

There are some options that can cause temp tables to materialize as
MyISAM tables or can be configured to delay it. Keep in mind that for
disk-based temp tables, there are no .frm files, but only .MYD and .MYI files (of course. the .MYI file is never used since it is impossible index an internal temp table).

Here are the options:

You should also consider the MySQL Documentation on Internal Temp Table Usage

The situations where in-memory temp tables are made are

  • If there is an ORDER BY clause and a different GROUP BY clause, or
    if the ORDER BY or GROUP BY contains columns from tables other than the
    first table in the join queue, a temporary table is created.
  • DISTINCT combined with ORDER BY may require a temporary table.
  • If you use the SQL_SMALL_RESULT option, MySQL uses an in-memory
    temporary table, unless the query also contains elements (described
    later) that require on-disk storage.

When an in-memory temp table exceeded the minimum of (tmp_table_size or max_heap_table_size), mysqld does the following:

  • Suspends the query
  • Copies the in-memory table's contents into a MyISAM temp table
  • Discards the in-memory table
  • Continues the query, sending the temp data into the MyISAM temp table

The situations where in-memory temp tables are bypassed in favor of disk are

  • Presence of a BLOB or TEXT column in the table
  • Presence of any column in a GROUP BY or DISTINCT clause larger than 512 bytes
  • Presence of any column larger than 512 bytes in the SELECT list, if UNION or UNION ALL is used

Some due diligence is required to reduce temp table creation on disk

  • Setting join_buffer_size bigger
  • Setting sort_buffer_size bigger
  • Setting tmp_table_size and max_heap_table_size bigger
  • Tuning queries to minimize or even prevent temp tables
  • Creating indexes to create presorted view of data from individual tables
  • Installing additional RAM to accommodate large in-memory temp tables

If after such due diligence, there are still temp tables being formed
on Disk, here is one desperate move: Mapping disk-based temp table
creation to memory.

Here is a quick-and-dirty way to set up a 16GB RAM Disk using tmpdir

STEP01) Create RAM Disk Folder

mkdir /var/mysql_tmpfs

STEP02) Add this to my.cnf

[mysqld]
tmpdir=/var/mysql_tmpfs

STEP03) Add this to /etc/fstab

echo "none /var/mysql_tmpfs tmpfs defaults,size=16g 1 2" >> /etc/fstab

STEP04) Reload /etc/fstab

mount -a

STEP05) service mysql restart

After this, all temp table that become MyISAM are written to the RAM Disk. This should speed disk-based temp table creation.

Give it a Try !!!

answered Dec 17 '12 at 23:19
RolandoMySQLDBA
63.4k1062148
 

These are queries that are rolling over onto disk because the results are too large for memory.

When the query is done, the space clears.

There's no way to match these temp files definitively to queries, but
you can get clues to make a good guess from SHOW FULL PROCESSLIST; or
SHOW INNODB STATUS; or by looking in your error log if the queries fail.

answered Dec 16 '12 at 5:50

 

Whenever we use alter statements on table It creates the
#sql_6405_3.MYD temporay files and once it's done throws the output and
disappears.

Alter on tables make MySQL to copy whole data into temporary files
#sql.xxx.MYD and make changes to created temporary files then drop
original data files tablename.MYD and renames the temporay files to
table name.

Also for some kinda sorting queries it creates temporary files.

As I traced out. This thing happens.

answered Dec 16 '12 at 13:48

Vinay
358
 

Your Answer

Why does MySQL produce so many temporary MYD files?的更多相关文章

  1. MySQL优化:explain using temporary

    什么时候会使用临时表:group/order没设计好的时候 1.order没用索引 2.order用了索引, 但不是和where相同的索引 3.order用了两个索引, 但不是联合索引 4.order ...

  2. MySQL提权之user.MYD中hash破解方法

    经常在服务器提权的时候,尤其是windows环境下,我们发现权限不高,却可以读取mysql的datadir目录,并且能够成功下载user.MYD这个文件.但是在读取内容的时候,经常会遇到root密码h ...

  3. mysql using filesort Using temporary

    using filesort 一般人的回答是: “当行数据太大,导致内存无法容下这些数据产生的临时表时,他们就会被放入磁盘中排序.”  很不幸,这个答案是错的 ,临时表在太大的时候确实会到磁盘离去,但 ...

  4. 一次mysql 优化 (Using temporary ; Using filesort)

    遇到一个SQL执行很慢 SQL 如下: SELECT ... FROM tableA WHERE time >= 1492044535 and time <= 1492046335 GRO ...

  5. MySQL调优 —— Using temporary

      DBA发来一个线上慢查询问题. SQL例如以下(为突出重点省略部分内容): select distinct article0_.id, 等字段 from article_table article ...

  6. 关于mysql 删除数据后(.MYD,MYI)物理空间未释放

    关于mysql 删除数据后物理空间未释放 OPTIMIZE TABLE 当您的库中删除了大量的数据后,您可能会发现数据文件尺寸并没有减小.这是因为删除操作后在数据文件中留下碎片所致.OPTIMIZE ...

  7. HOW MYSQL USES INTERNAL TEMPORARY TABLES

    HOW MYSQL USES INTERNAL TEMPORARY TABLES Table of Contents [hide] 1)UNION queries 2)Some views 3)SQL ...

  8. Mysql EXPLAIN 相关疑问: Using temporary ; Using filesort

    一.什么是Using temporary ; Using filesort 1. using filesort filesort主要用于查询数据结果集的排序操作,首先MySQL会使用sort_buff ...

  9. windows 下使用 zip安装包安装MySQL 5.7

    以下内容参考官方文档:http://dev.mysql.com/doc/refman/5.7/en/windows-start-command-line.html 解压缩zip到D:\mysql-5. ...

随机推荐

  1. 10.11 NOIP模拟题(1)

    /* 离散化 差分 */ #include<bits/stdc++.h> #define N 4000007 using namespace std; int n,ans; int tmp ...

  2. RabbitMq安装成功后执行命令报错(Error: unable to connect to node 'rabbit@DESKTOP-LPKSION': nodedown)

    我们直接来看解决方案吧.首先打开服务,找到RabbitMq服务. 双击打开后选择登陆选项卡: 点选此账户,输入你计算机的登录名称.点击浏览: 在这里输入你的用户名,点检索: 这里的密码输入你电脑开机登 ...

  3. npm install 安装软件,出现 operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache'

    问题如下图: 解决办法: 在开始菜单栏里打开cmd的时,右击选择“以管理员身份运行”.然后再在打开的cmd里运动install就没问题了. 这个问题应该是当时安装依赖时,我们是以管理员身份运行的:所以 ...

  4. 最新的 xp sp3序列号(绝对可通过正版验证)-xp序列号

    windows xp激活方法一:使用windows xp激活码 以下xp系统激活码都是可用的 MRX3F-47B9T-2487J-KWKMF-RPWBY(工行版) 可用(强推此号) QC986-27D ...

  5. Spark SQL概念学习系列之Spark SQL入门(八)

    前言 第1章   为什么Spark SQL? 第2章  Spark SQL运行架构 第3章 Spark SQL组件之解析 第4章 深入了解Spark SQL运行计划 第5章  测试环境之搭建 第6章 ...

  6. 16 继续讲C#中的条件执行。if...else if...else

    if...else...语句可以让我们判断两种情况.当条件为真的时候,执行一部分:当条件为假的时候,执行另一部分.如果我们需要判断3种,4种,5种情况,那我们应该怎么办呢? 在C#中我们可以 使用if ...

  7. VS2013使用单元测试

    一.开发环境 开发工具:VS2013 二.开发流程 1.添加一个控制台项目UnitDemo namespace UnitDemo { public class Program { static voi ...

  8. [ POI 2005 ] Bank Notes

    \(\\\) Description 给出 \(N\) 种货币的面值 \(b_i\) 和个数 \(c_i\) ,求最少需要用多少个硬币凑出 \(Q\) 元钱,并输出任意一种方案. \(n\le 200 ...

  9. input checkbox 选择内容输出多少个

    <input type="checkbox" name="qId" onclick="doit();"/><input t ...

  10. selenium学习第三天,新建一个测试用例(运行失败)。

    今天的意外收获,在找SELENIUM实例的时候,发现一个JS实例,功能各类非常全演示及代码都有,谢谢大神的分享:http://www.miniui.com/demo/#src=datagrid/pag ...