How to Manage Ibdata1 File Size in MySQL
MySQL's ibdata1 file stores essential data, but can grow excessively under certain usage patterns. This can become problematic, especially when using MySQL for specific purposes like query tool applications.
Causes of Ibdata1 File Growth
When using MySQL as a query tool, creating and dropping databases and tables frequently can lead to rapid ibdata1 file growth. This is because MySQL typically stores data and indexes of tables within the ibdata1 file by default.
Options for Managing Ibdata1 File Size
As of MySQL version 5.6.6, MySQL supports the use of separate files for each table. Enabling this feature prevents the ibdata1 file from growing excessively. To do this, add the following line to your my.cnf file:
innodb_file_per_table=1
To reclaim space used by ibdata1, follow these steps:
After restarting MySQL, ibdata1 and ib_log files will be recreated.
Using the ALTER TABLE or OPTIMIZE TABLE commands, you can extract data and index pages from ibdata1 to separate files. However, ibdata1 will not shrink unless you perform a full purge as described above.
Note on Information_Schema
Information_schema cannot be dropped and does not require its own file storage, as it utilizes the memory db-engine and is created/destroyed upon MySQL start/stop.
The above is the detailed content of How Can I Control the Size of My MySQL ibdata1 File?. For more information, please follow other related articles on the PHP Chinese website!