一个mysql/tmp目录爆满问题的处理-创新互联

突然收到zabbix告警,说mysql服务器的/目录磁盘空间不足。

成都创新互联是一家集网站建设,东台企业网站建设,东台品牌网站建设,网站定制,东台网站建设报价,网络营销,网络优化,东台网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

登录到服务器,看了下发现100GB的根目录,居然使用了差不多90GB。这台服务器上只跑了一个MySQL,应该不是日志未清理等其它原因造成的。

(说明:下面的几张截图是后期截的,当时已经有部分SQL跑完,释放掉部分磁盘空间了)

lsof |grep deleted 发现如下:

一个mysql /tmp目录爆满问题的处理可以看到这个临时文件差不多有40GB。

show processlist; 如下:

一个mysql /tmp目录爆满问题的处理

上图看的话,没有涉及到写binlog的操作,但是由于单纯的select并不会造成/tmp目录爆满的情况,所以猜测他这个同一个事务里面之前还有涉及到写binlog的操作(update、delete等)。

官方的说明:

https://dev.mysql.com/doc/refman/5.6/en/binary-log.html

When a thread that handles the transaction starts, it allocates a buffer of binlog_cache_size to buffer statements. If a statement is bigger than this, the thread opens a temporary file to store the transaction. The temporary file is deleted when the thread ends.

The Binlog_cache_use status variable shows the number of transactions that used this buffer (and possibly a temporary file) for storing statements. TheBinlog_cache_disk_use status variable shows how many of those transactions actually had to use a temporary file. These two variables can be used for tuning binlog_cache_size to a large enough value that avoids the use of temporary files.

The max_binlog_cache_size system variable (default 4GB, which is also the maximum) can be used to restrict the total size used to cache a multiple-statement transaction. If a transaction is larger than this many bytes, it fails and rolls back. The minimum value is 4096.

If you are using the binary log and row based logging, concurrent inserts are converted to normal inserts for CREATE ... SELECT or INSERT ... SELECTstatements. This is done to ensure that you can re-create an exact copy of your tables by applying the log during a backup operation. If you are using statement-based logging, the original statement is written to the log.

当事务开始时,它将缓冲区语句分配一个binlog_cache_size大小的缓冲区(我这里设置的是16777216bytes,即16MB)。 如果一个语句大于此,线程将打开一个临时文件来存储事务(默认是存放在/tmp/目录下)。 当线程结束时,临时文件会自动被删除。

上面就是因为事务里面的临时文件超过16MB了,被放到/tmp目录下了,但是这个临时文件实在太大了,导致磁盘空间不足告警了。

解决方法:

等上面的查询结束后,我们先关闭mysqld。(条件能允许的话,当然是让查询自己结束。如果直接kill掉的话,估计回滚也要话挺长时间的)

然后调整mysql的tmpdir到其他更大的磁盘去。

mkdir /bdata/mysql_tmp

chown mysql.mysql /bdata/mysql_tmp -R

chown 1777 -R /bdata/mysql_tmp -R

vim /etc/my.cnf

[mysqld]

tmpdir = /bdata/mysql_tmp

然后启动mysql即可

再次执行lsof|grep deleted 可以看到临时文件的路径已经改到了/bdata/mysql_tmp目录下了。

一个mysql /tmp目录爆满问题的处理

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

标题名称:一个mysql/tmp目录爆满问题的处理-创新互联
分享路径:https://www.cdcxhl.com/article36/cejhsg.html

成都网站建设公司_创新互联,为您提供App设计域名注册微信小程序商城网站营销型网站建设手机网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设