MYSQL大表联查缓冲区溢出问题思路

MYSQL大数据表联查(20W*20W)时报错, 小表查询正常,检查MYSQL服务器error.log:

210420 10:24:12 [ERROR] /usr/sbin/mysqld: Sort aborted: Error writing file '/tmp/MYxJWWvV' (Errcode: 28)

#查看详细MYSQL错误日志:
vi /var/log/mysql/error.log

210420 10:22:20 [ERROR] /usr/sbin/mysqld: Sort aborted: Error writing file '/tmp/MY0buVRE' (Errcode: 28)
210420 10:22:22 [ERROR] /usr/sbin/mysqld: Incorrect key file for table '/tmp/#sql_1ecb_0.MYI'; try to repair it
210420 10:22:22 [ERROR] Got an error from unknown thread, /build/mysql-5.5-xFqLis/mysql-5.5-5.5.60/storage/myisam/mi_write.c:226
210420 10:22:23 [ERROR] /usr/sbin/mysqld: Sort aborted: Error writing file '/tmp/MY21PWvi' (Errcode: 28)
210420 10:24:12 [ERROR] /usr/sbin/mysqld: Sort aborted: Error writing file '/tmp/MYxJWWvV' (Errcode: 28)

查询MYSQL-ERRCODE:28 可知磁盘空间不足,检查服务器可知磁盘正常:
@see perror命令

#检查ERROR:28错误原因:(No space left on device 磁盘空间不足)
root@DemoA:~# perror 28
OS error code  28:  No space left on device
root@DemoA:~# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/DemoA--vg-root   15G   13G  839M  94% /
none                        4.0K     0  4.0K   0% /sys/fs/cgroup
udev                        3.9G  4.0K  3.9G   1% /dev
tmpfs                       799M  532K  798M   1% /run
none                        5.0M     0  5.0M   0% /run/lock
none                        3.9G     0  3.9G   0% /run/shm
none                        100M     0  100M   0% /run/user
/dev/sda1                   236M  220M  4.0M  99% /boot
overflow                    1.0M  4.0K 1020K   1% /tmp
/dev/sdc                    9.8G   48M  9.2G   1% /mnt

经查BAIDU+BING+GOOGLE,发现可能为缓存目录不够导致TMPDIR="/tmp",只有1M,大表查询可能会出现磁盘不足错误,深入检查并实验后解决此问题:

# 增加磁盘挂载+100M到TMPDIR: 因为业务特殊原因不能修改/tmp目录位置
mount -o remount,size=100M tmpfs /tmp

# 检查挂载是否成功:/tmp -> 100M  [OK]
root@DemoA:~# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/DemoA--vg-root   15G   13G  839M  94% /
none                        4.0K     0  4.0K   0% /sys/fs/cgroup
udev                        3.9G  4.0K  3.9G   1% /dev
tmpfs                       799M  532K  798M   1% /run
none                        5.0M     0  5.0M   0% /run/lock
none                        3.9G     0  3.9G   0% /run/shm
none                        100M     0  100M   0% /run/user
/dev/sda1                   236M  220M  4.0M  99% /boot
overflow                    100M  4.0K  100M   1% /tmp
/dev/sdc                    9.8G   48M  9.2G   1% /mnt

重启MYSQL服务器进行验证

service mysql restart

查询成功!问题解决!

参考文档:
https://stackoverflow.com/questions/2090073/mysql-incorrect-key-file-for-tmp-table-when-making-multiple-joins/3716778#3716778

你可能感兴趣的:(MYSQL大表联查缓冲区溢出问题思路)