MySQL innodb_file_per_table Disk Space Management

This article explores how the innodb_file_per_table configuration affects disk space management in MySQL. We will examine the operational differences between storing all data in a single shared system tablespace versus utilizing individual table files, focusing on disk space reclamation, fragmentation, storage allocation, and administrative overhead.

Shared Tablespace vs. Individual Table Files

By default in modern MySQL versions, innodb_file_per_table is enabled. This setting dictates where InnoDB stores its data and indexes:

Reclaiming Disk Space

The most significant implication of the innodb_file_per_table setting lies in how the operating system reclaims disk space.

The Shared Tablespace Limitation

When innodb_file_per_table is disabled, dropping a table or deleting large volumes of rows does not reduce the physical size of the ibdata1 file on the operating system’s filesystem.

While InnoDB marks the deleted space as “free” internally and will reuse it for future inserts, the disk space remains allocated to MySQL. The only way to shrink a bloated ibdata1 file is to perform a full logical backup (using mysqldump or mysqlpump), stop the MySQL service, delete the database files, reinitialize the data directory, and restore the backup.

The File-Per-Table Advantage

When innodb_file_per_table is enabled, reclaiming disk space is straightforward:

Storage Fragmentation

Database fragmentation behaves differently depending on this setting:

OS-Level File Management and Performance

Using individual table files introduces operating system-level implications: