当前位置:网站首页>MySQL 20 MySQL data directory
MySQL 20 MySQL data directory
2022-07-06 10:37:00 【Protect our party a Yao】
One . MySQL8 The main directory structure of
find / -name mysql
Install well MySQL 8 after , Let's look at the following directory structure :
1.1. Storage path of database file
MySQL Storage path of database file :/var/lib/mysql/
show variables like 'datadir';
As can be seen from the results , On my computer MySQL The data directory is /var/lib/mysql/ .
1.2. Related command directory
Related command directory :/usr/bin(mysqladmin、mysqlbinlog、mysqldump Wait for the order ) and /usr/sbin.
1.3. Profile directory
Profile directory :/usr/share/mysql-8.0( Commands and configuration files ),/etc/mysql( Such as my.cnf)
Two . The relationship between database and file system
2.1. View the default database
Check what databases are currently on my computer :
SHOW DATABASES;
You can see that there is 4 A database belongs to MySQL Its own system database .
- mysql:MySQL The core database of the system , It stores MySQL User account and permission information , Some stored procedures 、 Event definition information , Some log information generated during operation , Some help information and time zone information .
- information_schema:MySQL The database of the system , This database holds MySQL The server Information about all other databases maintained , For example, what tables are there 、 Which views 、 Which triggers 、 Which columns 、 Which indexes . This information is not real user data , But some descriptive information , Sometimes it's called Metadata . In the system database information_schema Provides some information to innodb_sys Table at the beginning , Used to represent internal system tables .
- performance_schema:MySQL The database of the system , This database mainly stores MySQL Some status information during server operation , Can be used to monitor MySQL Various performance indicators of the service . Including statistics on which statements have been executed recently , How long did it take at each stage of the execution process , Memory usage and other information .
- sys: MySQL The database of the system , This database is mainly through View In the form of information_schema and performance_schema Combine , Help system administrators and developers monitor MySQL Technical performance .
2.2. The representation of a database in a file system
cd /var/lib/mysql
There are many files and subdirectories in this data directory , except information_schema This system is outside the database , Other databases are Data directory There are corresponding subdirectories under .
2.3. The representation of tables in the file system
2.3.1. InnoDB Storage engine mode
- Table structure
To save the table structure , InnoDB stay Data directory Under the corresponding database subdirectory, a special for Description of the file structure , The file name is like this :
Table name .frm
Let's say we're in MYSQLTEST Create a database named test Table of :
create table test(
c1 int
);
That's in the database MYSQLTEST A subdirectory named... Will be created under the corresponding subdirectory test.frm A file used to describe the table structure ..frm The format of the file is the same on different platforms . The suffix is .frm In order to Binary format Stored , It's garbled when we open it directly .
- Data and indexes in the table
① SYSTEM tablespace (system tablespace)
By default ,InnoDB Will create a data directory named ibdata1 、 The size is 12M The file of , This file is the corresponding SYSTEM tablespace Representation on the file system . How to 12M? Note that this file is 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 file system , Or just feel the original ibdata1 The file name is ugly , That can be in MySQL Configure the corresponding file paths and their sizes at startup , For example, let's modify it like this my.cnf The configuration file :
[server]
innodb_data_file_path=data1:512M;data2:512M:autoextend
② 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 table data , 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 used Independent table space De storage MYSQLTEST Database based test Words of watch , Then, in the database where the table is located atguigu The directory will be test The table creates these two files :
test.frm
test.ibd
among test.ibd Files are used to store test Data and indexes in tables .
③ Setting of system table space and independent table space
We can use it by ourselves SYSTEM tablespace still Independent table space To store data , This function is controlled by the startup parameters innodb_file_per_table control , For example, we want to deliberately store the table data in SYSTEM tablespace when , 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
④ Other types of tablespaces
With MySQL The development of , In addition to the above two old table spaces , A number of different types of table spaces have been proposed , For example, common table spaces (general tablespace)、 Temporary table space (temporary tablespace) etc. .
2.3.2. MyISAM Storage engine mode
- Table structure
In terms of storage table structure , MyISAM and InnoDB equally , Also in Data directory A file dedicated to describing the table structure is created under the corresponding database subdirectory :
Table name .frm
- Data and indexes in the table
stay MyISAM The indexes in are all Secondary indexes , Of the storage engine Data and index are stored separately Of . Therefore, different files are also used in the file system to store data files and index files , At the same time, the table data are stored in the corresponding database subdirectory . If test Table use MyISAM Storage engine , Then, in the database where it is located MYSQLTEST The directory will be test The table creates these three files :
test.frm Storage table structure
test.MYD Store the data (MYData)
test.MYI Storage index (MYIndex)
Create a MyISAM surface , Use ENGINE Option to explicitly specify the engine . because InnoDB Is the default engine .
2.4. Summary
give an example : database a , surface b .
- If the table b use InnoDB ,data\a There will be 1 A or 2 File :
- b.frm : Description table structure file , Field length, etc .
- If the SYSTEM tablespace Mode , Data information and index information are stored in ibdata1 in .
- If the Independent table space Storage mode ,data\a There will also be b.ibd file ( Store data information and index information ).
Besides :
① MySQL5.7 Will be in data/a Generated in the directory of db.opt File is used to save the relevant configuration of the database . such as : Character set 、 Compare the rules . and MySQL8.0 No more db.opt file .
② MySQL8.0 Is no longer available separately b.frm, But merge in b.ibd In file .
- If the table b use MyISAM ,data\a There will be 3 File :
- MySQL5.7 in : b.frm : Description table structure file , Field length, etc .
- MySQL8.0 in b.xxx.sdi : Description table structure file , Field length, etc .
- b.MYD (MYData): Data information file , Store data information ( If the independent table storage mode is adopted ).
- b.MYI (MYIndex): Store index information file .
边栏推荐
- MySQL transaction log
- 【C语言】深度剖析数据存储的底层原理
- Mysql27 index optimization and query optimization
- Security design verification of API interface: ticket, signature, timestamp
- Pytoch LSTM implementation process (visual version)
- How to find the number of daffodils with simple and rough methods in C language
- Isn't there anyone who doesn't know how to write mine sweeping games in C language
- MySQL34-其他数据库日志
- February 13, 2022 - Maximum subarray and
- C language string function summary
猜你喜欢
MySQL27-索引優化與查詢優化
MySQL30-事务基础知识
Use xtrabackup for MySQL database physical backup
Mysql23 storage engine
UEditor国际化配置,支持中英文切换
MySQL35-主从复制
A necessary soft skill for Software Test Engineers: structured thinking
Database middleware_ MYCAT summary
使用OVF Tool工具从Esxi 6.7中导出虚拟机
If someone asks you about the consistency of database cache, send this article directly to him
随机推荐
Export virtual machines from esxi 6.7 using OVF tool
Security design verification of API interface: ticket, signature, timestamp
What is the current situation of the game industry in the Internet world?
该不会还有人不懂用C语言写扫雷游戏吧
Technology | diverse substrate formats
高并发系统的限流方案研究,其实限流实现也不复杂
How to build an interface automation testing framework?
ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
Emotional classification of 1.6 million comments on LSTM based on pytoch
Jar runs with error no main manifest attribute
Transactions have four characteristics?
Software test engineer development planning route
Case identification based on pytoch pulmonary infection (using RESNET network structure)
使用OVF Tool工具从Esxi 6.7中导出虚拟机
15 medical registration system_ [appointment registration]
实现以form-data参数发送post请求
Mysql26 use of performance analysis tools
Google login prompt error code 12501
[after reading the series] how to realize app automation without programming (automatically start Kwai APP)
MySQL combat optimization expert 03 uses a data update process to preliminarily understand the architecture design of InnoDB storage engine