当前位置:网站首页>[MySQL from introduction to mastery] [advanced part] (II) representation of MySQL directory structure and tables in the file system
[MySQL from introduction to mastery] [advanced part] (II) representation of MySQL directory structure and tables in the file system
2022-06-26 13:31:00 【Man Nong Feige】
Hello! , I'm Manon Feige , Thank you for reading this article , Welcome to three links with one button .
1. Python Basic column , Basic knowledge in a net ,9.9 Yuan can't buy a loss , I can't buy it . Python From entry to mastery
️ 2. Python Crawler column , Systematically learn the knowledge points of reptiles .9.9 Yuan can't buy a loss , I can't buy it .python Reptile beginner level
️ 3. Ceph actual combat , Everything from principle to actual combat . Ceph actual combat
️ 4. Java Introduction to high concurrency programming , Punch in to learn Java High concurrency . Java Introduction to high concurrency programming
5. Take a stroll around the community , Weekly benefits , There are surprises every week . Manon Feige community , Leap plan
The whole network has the same name 【 Manon Feige 】 Welcome to your attention , personal VX: wei158556
List of articles
1. brief introduction
Install well mysql after , We can go through find / -name mysql Command view mysql File or folder . As shown in the figure below , There must be something marked in red .
Here is a brief introduction to the core directory :
1.1. MySQL Storage path of database file :/var/lib/mysql.

The parts marked with red boxes in the above figure are all MySQL Database in :
among : database demodb1,test,testdb1 The three databases are created by users themselves .
database mysql,information_schema,performance_schema,sys All four databases are MySQL The database that comes with it . More on that later .
MySQL When the server program starts, it will load some files in a directory of a certain system of the file system , After that, the data generated during operation will also be stored in some files in this directory , This directory is called the data directory .
Actually, the data directory corresponds to a system variable datadir, We can check the value of this system variable after establishing a connection between the client and the server ;
mysql> show variables like 'datadir';

1.2. Related command directory /usr/bin(mysqladmin、mysqlbinlog、mysqldump Wait for the order ) and /usr/sbin.
The installation directory is very important bin Catalog , It stores many commands about controlling client programs and server programs ( Many executables , such as mysql,mysqld etc. ). The data directory is used to store MySQL Data generated during operation .
1.3. Profile directory
Profile directory :/usr/share/mysql( Commands and configuration files ),/etc/my.cnf.
2. The relationship between database and file system
image InnoDB、MyISAM Such a storage engine stores tables on disk , The structure used by the operating system to manage the disk is called the file system , So to put it in professional terms is : image InnoDB、MyISAM Such storage engines store tables on the file system . When we want to read data , These storage engines will read the data from the file system and return it to us , When we want to write data , These storage engines will write the data back to the file system .
Check what databases are currently in my computer :
mysql> show databases;

among : database demodb1,test,testdb1 The three databases are created by users themselves .
database mysql,information_schema,performance_schema,sys All four databases are MySQL The database that comes with it .
| database | meaning |
|---|---|
| mysql | Storage MySQL All kinds of information required for the normal operation of the server ( The time zone 、 Master-slave 、 user 、 Authority, etc ) |
| information_schema | Provides various tables and views for accessing database metadata , Include database 、 surface 、 Field type and access rights, etc |
| performance_schema | by MySQL Server runtime status provides an underlying monitoring function , Mainly used to collect database server performance parameters |
| sys | Contains a series of convenient DBA And developers take advantage of performance_schema View of performance database for performance tuning and diagnosis |
2.1. mysql A brief description of the library
We can go through show tables Command to view all data tables under a database .
stay mysql In the database user Table most commonly used , This table stores all the available MySQL User information of the server .
2.1. information_schema A brief description of the library
information_schema The main function of the library is to store various tables and views of database metadata , Include database 、 surface 、 Field type and access rights, etc .
We have the execution ahead show databases as well as show tables Command is actually from information_schema Pull data from the corresponding data table in the library .
information_schema The tables in save various database information .
| Data sheet | The corresponding order | Store content |
|---|---|---|
| ENGINES | show engines; | Data engine |
| SCHEMATA | show databases; | All databases that the current user can see |
| TABLES | show tables; | All data tables that the current user can see |
| COLUMNS | show columns from table_name | All columns under the data table |
| STATISTICS | show index from table_name | Index under data table |
| PROCESSLIST | show processlist | Thread under data table |
2. The representation of a database in a file system
Use CREATE DATABASE Database name Statement to create a database , What actually happens on the file system ? Actually , Each database corresponds to a subdirectory under the data directory , Or corresponding to a folder , Whenever you create a new database ,MySQL Will help us do these two things ;
- Create a subdirectory with the same name as the database under the data directory .
- Create a subdirectory named... Under the same name as the database name db.opt The file of ( Is limited to MySQL 5.7 And previous versions ), This file contains various properties of the database , For example, the character set and comparison rules of the database .
2.1. Data and indexes in the table
Reserve knowledge : InnoDB In fact, the page is used as the basic unit to manage the storage space , The default page size is 16KB.
about InnoDB For storage engines , Each index corresponds to a tree B+ Trees , The B+ Each node of the tree is a data page , Data pages need not be physically contiguous , Because there is a two-way linked list between data pages to maintain the order of these pages .
InnoDB The leaf node of the cluster index of stored complete user records , That is to say, index is data , Data is index .
In order to better manage these pages ,InnoDB Propose a table space or file space ( English name :table space perhaps file space) The concept of , This table space is an abstract concept , It can correspond to one or more real files on the file system ( The number of files corresponding to different tablespaces may be different ). Each table space can be divided into many pages , Our table space is stored in some pages under a table space . There are different types of tablespaces here . Data directory /var/lib/mysql.
2.1.1. SYSTEM tablespace (system tablespace)
By default ,InnoDB Will create a data directory named ibdata1、 The size is 12MB The file of , This file is the representation of the corresponding system table space on the file system . How to 12MB? Note that this file is a self expanding file , When it is not enough, it will increase the file size by itself .
Of course , If you want the system table space to correspond to multiple actual files on the system , Or just feel the original ibdata1. We can do it in MySQL Configure the corresponding file paths and their sizes at startup , For example, we can modify my.cnf The configuration file :
[server]
innodb_data_file_path=data1:512M;data2:512M;autoextend
In this way MySQL These two will be created after startup 512MB The size of the file system as the table space , Among them autoextend Indicates that the two files will be automatically expanded if they are not enough data2 File size .
2.1.2. Independent table space (file-per-table tablespace)
stay MySQL5.6.6 And later versions ,InnoDB It does not store the data of each table in the system table space by default , But for Each table establishes an independent table space , That is to say, how many tables have we created , There are just as many independent table spaces , Use Independent table space To store data tables , A file representing the independent table space will be created under the corresponding subdirectory of the database to which the table belongs , The file name is the same as the table name , Just added one .ibd
It's just an extension of , So the full file name is like this .
Table name .ibd
such as : We use a separate table space to store testdb1 Database based testtable1 Words of watch , Then, in the database where the table is located testdb1 The directory will be testtable1 The table creates these two files :
among :testtable1.ibd Files are used to store test Table data and index .
2.1.3. Setting of system table space and independent table space
We can specify for ourselves whether to use a system table space or a separate table space to store data , This function is controlled by the startup parameters innodb_file_per_table control , For example, we want to store the table data in the system table space , Can be started at MySQL The server is configured like this .
[server]
innodb_file_per_table=0 #0: Represents the use of system tablespaces ,1: Represents the use of independent tablespaces
By default :
explain :innodb_file_per_table Parameter modification only affects the newly created table , It does not work for data tables that have allocated tablespaces , If we want to move tables that already exist in the system table space to a separate table space , You can use the following syntax :
ALTER TABLE Table name TABLESPACE[=]innodb_file_per_table;
3. summary
Data directory /var/lib/mysql,MySQL The data in the database eventually falls into the disk file system .
边栏推荐
- 三维向量的夹角
- Bridge mode
- Here document interaction free and expect automatic interaction
- 适配器模式(Adapter)
- 7-2 the cubic root of a number
- Wechat applet magic bug - choose to replace the token instead of clearing the token, wx Getstoragesync will take the old token value instead of the new token value
- 5+api, clear application cache
- Es6: iterator
- 李航老师新作《机器学习方法》上市了!附购买链接
- Oplg: new generation cloud native observable best practices
猜你喜欢

Basic configuration and test of Beifu twincat3 NCI in NC axis interface

12 SQL optimization schemes summarized by old drivers (very practical)

Teacher Li Hang's new book "machine learning methods" is on the market! Purchase link attached

输入文本自动生成图像,太好玩了!

Here document interaction free and expect automatic interaction

Es sauvegarde et restauration des données par instantané

Es snapshot based data backup and restore

ES基於Snapshot(快照)的數據備份和還原

Use of wangeditor rich text editor

Arcpy——InsertLayer()函数的使用:掺入图层到地图文档里
随机推荐
Electron official docs series: Best Practices
2、并行接口、协议和相关芯片介绍(8080、8060)
Arcpy——InsertLayer()函數的使用:摻入圖層到地圖文檔裏
[how to connect the network] Chapter 2 (next): receiving a network packet
Appearance mode (facade)
Oplg: new generation cloud native observable best practices
【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示
A few lines of code can realize complex excel import and export. This tool class is really powerful!
Prototype
KITTI Detection dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
HDU 3709 Balanced Number
Typescript
G - Cow Bowling
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
Sed editor
33、使用RGBD相机进行目标检测和深度信息输出
Map value
[how to connect the network] Chapter 2 (middle): sending a network packet
装饰器(Decorator)
LAMP编译安装