天天看點

[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