Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean or resize the ibtmp1 file in MySQL?

MySQL 5.7 introduces a new file ibtmp1 for storing temporary data in InnoDB to increase the performance.

But I have noted that its size increases continuously. On my db server its sizes increases to 92GB.

Is there any way of reducing size or deleting the file without restarting the server ?

Thanks

like image 963
Aman Aggarwal Avatar asked Dec 19 '16 06:12

Aman Aggarwal


People also ask

How do I find the temp tablespace size in MySQL?

The TotalSizeBytes value reports the current size of the temporary tablespace data file. For information about other field values, see Section 24.3. 9, “The INFORMATION_SCHEMA FILES Table”. Alternatively, check the temporary tablespace data file size on your operating system.

What is Ibdata file in MySQL?

The file ibdata1 is the system tablespace for the InnoDB infrastructure. It contains several classes for information vital for InnoDB. Table Data Pages. Table Index Pages. Data Dictionary.


2 Answers

The ibtmp1 once created can't be shrink by any method without restarting mysql service.

There are two ways to handle it:

Precaution : At the time of server start you should limit the size of this file as:

 innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G 

where max 5G means this file size limits to 5GB.

Cure : If file already created you need to restart service:

SET GLOBAL innodb_fast_shutdown = 0; Shutdown MySQL remove ibtmp1 start MySQL. 

Docs: https://dev.mysql.com/doc/refman/5.7/en/innodb-temporary-tablespace.html

like image 188
Aman Aggarwal Avatar answered Sep 30 '22 20:09

Aman Aggarwal


In mysql 5.7 and higher all you need to do to reclaim the space used by the ibtmp1 file is restart the service.

You do not have to set GLOBAL innodb_fast_shutdown = 0; or manually delete the file.

like image 32
Geoff_Clapp Avatar answered Sep 30 '22 21:09

Geoff_Clapp