[MySQL study notes (eight)] introduction to the data directory structure

This article is published by the official account [Developing Pigeon]! Welcome to follow! ! !


Old Rules-Sister Town House:

One. MySQL data directory

(1) Data Catalog

       When the MySQL server program starts, it returns to a certain directory of the file system to load some data, and the data generated during the running process will also be stored in some files under this directory. This directory is called the data directory. Note that it must be distinguished from the mysql installation directory. To determine the data directory path, you can view it through the system variable datadir.

SHOW VARIABLES LIKE ‘datadir’;

(2) The structure of the data directory

       What data will MySQL save? User data such as created databases, tables, views, and triggers, as well as some additional data.

1. Database

       Whenever a database is created, the data directory will create a subdirectory with the same name as the database. At the same time, a file named db.opt is created in the subdirectory, which contains some attributes of the database, such as character set and comparison rules. Except for the information_schema system database that does not have a corresponding subdirectory for the database in MySQL, there are other databases.


2. Table

       The data is inserted into the table in the form of records, and the information of each table is divided into the definition of the table structure and the data in the table. Both InnoDB and MyISAM have created a file dedicated to describing the table structure in the database subdirectory: table name.frm, which is stored in binary format.

(1) Table in InnoDB

       For the data in the table, different storage engines are not the same. For InnoDB, first manage data in units of pages, and use table spaces to manage these pages. Table space is an abstract concept. It corresponds to one or more real files on the file system. Each table space is divided into multiple pages. There are multiple types of table spaces. The system tablespace corresponds to one or more actual files on the file system. By default, InnoDB will create a system tablespace file named ibdata1 with a size of 12MB in the data directory. The file is self-expanding and the file size can be Modified through system variables. There is only one copy of the system tablespace in a MySQL server.

       After MySQL 5.6.6, InnoDB no longer stores the data of each table in the system table space by default, but creates an independent table space for each table. The file name is: table name.ibd. There are some other types of table spaces, such as general table spaces, undo table spaces, temporary table spaces and so on.

(2) Table in MyISAM

       Since the indexes in MyISAM are all secondary indexes, the data and indexes of the storage engine are stored separately, so different files are used in the file system to store data files and index files, and table data and indexes are also stored in the corresponding In the subdirectory of the database, table name .MYD represents the data file of the table, and table name .MYI represents the index file of the table.

3. Other documents

       Server process files, log files, certificate and key files.

(3) Introduction to MySQL system database

1. mysql

       Store mysql user account and permission information, logs, help information, etc.


2. information_schema

       The information of all other databases maintained by the mysql server, such as which tables, which views, which triggers, which columns, which indexes, are not real user data, but descriptive information, called metadata.

3. performance_schema

       Save the state information during the operation of the mysql server, which is the performance monitoring of the operation state of mysql.

4. sys

       Combining information_schema and performance_schema in the form of views makes it easier for developers to understand the performance information of the mysql server.

Guess you like

Origin blog.csdn.net/Mrwxxxx/article/details/113829357