临时表过大

今天遇到一个这样的错误:

ERROR 126 (HY000): Incorrect key file for table '/tmp/#sql_dbd_0.MYI'; try to repair it

发现其原因是临时表太大了,而/tmp分区只有2G,放不下就报错了。
sql是这样的:

select promotion.promotion_id,
client.* ,
thanks.thanks_id,
thanks.thanks_type,
draft.draft_id,
rand() as s
from promotion, client, thanks, draft
where promotion.client_id = client.client_id
and promotion.promotion_id = thanks.promotion_id
and promotion.promotion_id = draft.promotion_id
order by s
limit 10

如果把中间结果自己建一个临时表

create temporary table tmp select ...

建出的表文件只有100M左右,那么为什么/tmp中会放不下呢?
猜测MySQL自己建的临时表都是静态行(没有找到资料证实)。有这样的猜测是因为如果用

create temporary table tmp row_format=fixed select ...

建表就会出现同样的错误了。

ERROR 126 (HY000): Incorrect key file for table '/tmp/#sqldbd_6bd_0.MYI'; try to repair it

所以这个问题有两个解决方法:
1. 自己建临时表
2. 加大临时目录。可以加大/tmp分区,也可以在启动MySQL时设置TMPDIR环境变量指定另外的临时目录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值