天天看点

[MySQL] ibtmp文件过大怎么处理?

ibtmp文件过大怎么处理?它到底是什么?如何才能彻底的解决此问题呢?

对于存储数据的Innodb引擎而言,独立表空间和通用的表空间都是以.ibd文件结尾;对于Undo文件来讲是以undo为前缀的;系统表空间的前缀是ibdata;临时表空间的前缀为ibtmp。如果没有特殊说明的话,此文件通常都在datadir目录下。我们此文所讲的就是临时表空间过大的问题解决(预防)方式。只对于innodb而言。

通过前一段我们已经了解了ibtmp文件的含义,那么它如果过大的话,该怎么办呢?下面我们先引入一段官方文档的原话:

The temporary tablespace is removed on normal shutdown or on an aborted initialization. The temporary tablespace is not removed when a crash occurs. In this case, the database administrator may remove the temporary tablespace manually or restart the server with the same configuration, which removes and recreates the temporary tablespace.

通过此段话,我们很清楚的看到,ibtmp文件过大清理的话,我们是必须要重启数据才会生效。什么?重启数据库对于不能停止的业务来说,肯定不能接受了。那么我们应该怎么办呢?才能彻底解决ibtmp文件过大的产生呢?下面这个参数就可以彻底解决ibtmp文件过大的问题了。

innodb_temp_data_file_path(5.7中引入的参数)

innodb_temp_data_file_path=ibtmp1:50M:autoextend:max:500MB

参考官网链接:

https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_temp_data_file_path https://dev.mysql.com/doc/refman/5.7/en/glossary.html#glos_temporary_table https://dev.mysql.com/doc/refman/5.7/en/glossary.html