36

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

Aman Aggarwal
  • 17,619
  • 9
  • 53
  • 81

3 Answers3

47

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

Avatar
  • 14,622
  • 9
  • 119
  • 198
Aman Aggarwal
  • 17,619
  • 9
  • 53
  • 81
  • 1
    Running AWS RDS MySQL 5.7, a "failover-with-reboot" was sufficient to truncate this file. – Alex Jan 18 '19 at 05:43
  • 1
    this question was particular for native mysql not for cloud. – Aman Aggarwal Jan 20 '19 at 03:02
  • 9
    Mini-Tutorial: Edit file `/etc/mysql/mysql.conf.d/mysqld.cnf`. Add as last line: `innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G` (or xG). Restart Mysql: `sudo service mysql restart` --- Check the file size at `/var/lib/mysql/ibtmp1`. – Avatar Oct 07 '19 at 10:22
  • I found it was unnecessary to remove ibtmp1, the file was resized when I restarted the mysql service. Ver 14.14 – Jon Hulka Mar 04 '20 at 17:09
  • 1
    @JonHulka the question is how to remove if you can't restart - So precaution is better than cure.. – Aman Aggarwal Mar 05 '20 at 09:47
  • @AmanAggarwal Precaution works both ways. I was erring on the side of doing as little as possible to mess with how MySQL manages its data - it probably makes no difference. I've had a bad experience in the past moving ib* files around. I didn't have to restart the server, just the MySQL service. – Jon Hulka Mar 05 '20 at 18:27
6

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.

Geoff_Clapp
  • 161
  • 1
  • 5
4

To solve this problem just do the following steps:

1- run this command:
sudo nano /etc/mysql/my.cnf

2- Add the following row under [mysqld] row
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G

3- Save the file.

4- Now we need to free up some disk space and delete ibtmp1, we can do that by restarting the SQL server:

sudo service mysql restart

Mohamad Hamouday
  • 2,070
  • 23
  • 20