You are on page 1of 1

Ghi chu ve type innodb trong mysql

InnoDB stores all databases in one file (ibdata1 by default).


There are two basic infrastructures
innodb_file_per_table disabled
innodb_file_per_table enabled
InnoDB (innodb_file_per_table disabled)
With innodb_file_per_table disabled, all these types of InnoDB info live within
ibdata1. The only manifestation of any InnoDB table outside of ibdata1 is the .f
rm file of the InnoDB table. Copying all InnoDB data at once requires copying al
l of /var/lib/mysql.
Copying an individual InnoDB table is totally impossible. You must mysqldump to
extract a dump of the table as a logical representation of the data and its corr
esponding index definitions. You would then load that dump to another database o
n the same server or another server.
InnoDB (innodb_file_per_table enabled)
With innodb_file_per_table enabled, table data and its indexes live in the datab
ase folder next to the .frm file. For example, for the table db1.mytable, the ma
nifestation of that InnoDB table outside of ibdata1 would be:
/var/lib/mysql/db1/mytable.frm
/var/lib/mysql/db1/mytable.ibd
System Tablespace ibdata1
All the metadata for db1.mytable still resides in ibdata1 and there is absolutel
y no way around that. Redo logs and MVCC data also still live with ibdata1.
When it comes to table fragmentation, here is what happens to ibdata1:
innodb_file_per_table enabled: you can shrink db1.mytables with ALTER TABLE db1.
mytable ENGINE=InnoDB; or OPTIMIZE TABLE db1.mytable;. This results in /var/lib/
mysql/db1/mytable.ibd being physically smaller with no fragmentation.
innodb_file_per_table disabled: you cannot shrink db1.mytables with ALTER TABLE
db1.mytable ENGINE=InnoDB; or OPTIMIZE TABLE db1.mytable; because it resides wit
h ibdata1. Running either command actually make the table contiguous and faster
to read and write to. Unfortunately, that occurs at the end of ibdata1. This mak
es ibdata1 grow rapidly. This is fully addressed in my InnoDB Cleanup Post.
When innodb_file_per_table is OFF and all data is going to be stored in ibdata f
iles. If you drop some tables of delete some data then there is no any other way
to reclaim that unused disk space except dump/reload method.
When Innodb_file_per_table is ON, each table stores data and indexes in it s own t
ablespace file. However, the shared tablespace-ibdata1 can still grow and you ca
n check more information here about why it grows and what are the solutions.

You might also like