Mysql – Huge #sql-xxxx_xxxx.ibd files in thesql-data folder

innodbMySQL

On one of our mysql databases the size on disk is way larger (28GB) than the actual data (~5GB) so I had a closer look to the files contained in mysql-data

I see the following files

12K     #sql-5254_eaa3.frm
8.9G    #sql-5254_eaa3.ibd
12K     #sql-537f_8d5b.frm
11G     #sql-537f_8d5b.ibd

The above remain even after mysql restart, server reboot etc

Any idea if these are temporary tables that survived e.g. a crash? on a production system is it safe to just remove them or do I need to handle them in a different way?

By the way we do have file_per_table set to true.

thanks in advance for any hints!

Best Answer

The table files you are seeing are most likely resulting from an ALTER TABLE operation which could not be completed. The relevant portion of the MySQL docs says:

If MySQL crashes in the middle of an ALTER TABLE operation, you may end up with an orphaned temporary table inside the InnoDB tablespace. Using the Table Monitor, you can see listed a table with a name that begins with #sql-. You can perform SQL statements on tables whose name contains the character “#” if you enclose the name within backticks. Thus, you can drop such an orphaned table like any other orphaned table using the method described earlier. To copy or rename a file in the Unix shell, you need to put the file name in double quotation marks if the file name contains “#”.

so I would simply issue a DROP TABLE on them. Note: Do not simply delete the files - otherwise you will get so called orphaned tables yielding database engine warnings like these:

InnoDB: in InnoDB data dictionary has tablespace id N,
InnoDB: but tablespace with that id or name does not exist. Have
InnoDB: you deleted or moved .ibd files?
InnoDB: This may also be a table created with CREATE TEMPORARY TABLE
InnoDB: whose .ibd and .frm files MySQL automatically removed, but the
InnoDB: table still exists in the InnoDB internal data dictionary.
Related Topic