Chapter 02 MySQL Data Directory

Chapter 02 MySQL Data Directory

1. Main directory structure of MySQL8
find / -name mysql
1.1 Storage path of database files
show variables like 'datadir'; # /var/lib/mysql/
1.2 Related command directories

Related command directories: /usr/bin and /usr/sbin.

1.3 Configuration file directory

Configuration file directory: /usr/share/mysql-8.0 (command and configuration files), /etc/mysql (such as my.cnf)

2. Relationship between database and file system
2.1 Representation of tables in file systems
2.3.1 InnoDB storage engine mode

1. Table structure

In order to save the table structure, a dedicated database is created InnoDBin the数据目录描述表结构的文件

表名.frm

2. Data and indexes in the table

① System tablespace (system tablespace)

By default, InnoDB will create a file named and size in the data directory . ibdata1This file is the corresponding representation on the file system.12M自拓展系统表空间

② Independent tablespace (file-per-table tablespace)

In MySQL 5.6.6 and later versions, InnoDB does not store the data of each table in the system table space by default, but instead 每一个表建立一个独立表空间stores the data of each table in the system table space. In other words, there are as many independent table spaces as there are tables we create. If used 独立表空间to store table data, a file representing the independent table space will be created in the subdirectory corresponding to the database to which the table belongs. The file name is the same as the table name.

表名.ibd

MySQL8.0 is no longer provided separately 表名.frm, but is merged in 表名.ibdthe file.

③ Settings of system table space and independent table space

We can specify 系统表空间whether to use 独立表空间or store data ourselves. This function innodb_file_per_tableis controlled by startup parameters.

[server] 
innodb_file_per_table=0 # 0:代表使用系统表空间; 1:代表使用独立表空间

④ Other types of table spaces

With the development of MySQL, in addition to the above two old table spaces, some different types of table spaces are now proposed, such as general tablespace, temporary tablespace, etc.

2.3.2 MyISAM storage engine mode

1. Table structure

In terms of storing table structures, MyISAM, like InnoDB, 数据目录also creates a file specifically used to describe the table structure in the corresponding database subdirectory.

表名.frm

2. Data and indexes in the table

All indexes in MyISAM belong 二级索引to the storage engine 数据和索引是分开存放. Therefore, different files are also used in the file system to store data files and index files, and table data are stored in the corresponding database subdirectories.

test.frm 存储表结构 #MySQL8.0 改为了 b.xxx.sdi
test.MYD 存储数据 (MYData) 
test.MYI 存储索引 (MYIndex

Guess you like

Origin blog.csdn.net/github_36665118/article/details/134139062