当前位置:网站首页>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 .
边栏推荐
- A necessary soft skill for Software Test Engineers: structured thinking
- Implement context manager through with
- [leectode 2022.2.13] maximum number of "balloons"
- 软件测试工程师发展规划路线
- MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
- February 13, 2022-2-climbing stairs
- Const decorated member function problem
- MNIST implementation using pytoch in jupyter notebook
- Set shell script execution error to exit automatically
- 第一篇博客
猜你喜欢
![15 medical registration system_ [appointment registration]](/img/c1/27c7a5aae82783535e5467583bb176.png)
15 medical registration system_ [appointment registration]

Export virtual machines from esxi 6.7 using OVF tool

MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database

Mysql25 index creation and design principles

ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()

Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)

MySQL storage engine

MySQL25-索引的创建与设计原则

Emotional classification of 1.6 million comments on LSTM based on pytoch

Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
随机推荐
MySQL22-逻辑架构
Mysql26 use of performance analysis tools
Global and Chinese markets of static transfer switches (STS) 2022-2028: Research Report on technology, participants, trends, market size and share
Anaconda3 installation CV2
What is the difference between TCP and UDP?
Global and Chinese market of transfer switches 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL29-数据库其它调优策略
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
UEditor国际化配置,支持中英文切换
Global and Chinese market of thermal mixers 2022-2028: Research Report on technology, participants, trends, market size and share
如何搭建接口自动化测试框架?
Mysql35 master slave replication
Mysql33 multi version concurrency control
MySQL31-MySQL事务日志
Water and rain condition monitoring reservoir water and rain condition online monitoring
高并发系统的限流方案研究,其实限流实现也不复杂
text 文本数据增强方法 data argumentation
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
Global and Chinese market for intravenous catheter sets and accessories 2022-2028: Research Report on technology, participants, trends, market size and share
Nanny hand-in-hand teaches you to write Gobang in C language