🌐 中文 English
This article aims to introduce the directory structure related to tables in MySQL on Linux.
Directory Where MySQL Stores Tables
The directory structure for storing data in the database is as follows:
1
cd /var/lib/mysql
Select a database folder to enter and view the table files within it.
Table Files for Different Engines
In the InnoDB engine,
- In MySQL 5.7, table files have the suffix .ibd, and table data files have the suffix .frm.
- In MySQL 8.0, table files have the suffix .ibd, and table data is also written into them.
You can use the
ibd2sdicommand to convert .ibd files to .txt files for viewing.1
ibd2sdi --dump-file=table.txt table.ibd
In the
MyISAMengine, - The files storing table data are .MYD (data) and .MYI (index).
- The file storing table structure is .frm.
Independent Tablespace and System Tablespace
- Independent tablespace (after MySQL 5.66): Tablespace files and table structure files are stored separately in the database folder.
- System tablespace (before MySQL 5.66):
Tablespace files and table structure files are stored together in a single file under
/var/lib/mysql. (You can add theinnodb_file_per_tableparameter under the[server]section in the my.cnf file and assign the corresponding value: 0 represents using the system tablespace; 1 represents using the independent tablespace.)
Views
A view is a virtual table that does not store data, so it only generates a .frm file.
Summary
- The suffix of table files depends on the storage engine type.
- The difference between independent tablespace and system tablespace lies in the storage location of tablespace files and table structure files.
- A view is a virtual table that does not store data, so it only generates a .frm file.