当前位置:网站首页>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 .
边栏推荐
- If someone asks you about the consistency of database cache, send this article directly to him
- February 13, 2022-2-climbing stairs
- Mysql27 index optimization and query optimization
- MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
- Sed text processing
- How to change php INI file supports PDO abstraction layer
- Security design verification of API interface: ticket, signature, timestamp
- MySQL29-数据库其它调优策略
- Security design verification of API interface: ticket, signature, timestamp
- Super detailed steps for pushing wechat official account H5 messages
猜你喜欢
MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?
14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]
保姆级手把手教你用C语言写三子棋
Mysql26 use of performance analysis tools
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
What should the redis cluster solution do? What are the plans?
MySQL Real Time Optimization Master 04 discute de ce qu'est binlog en mettant à jour le processus d'exécution des déclarations dans le moteur de stockage InnoDB.
MySQL combat optimization expert 12 what does the memory data structure buffer pool look like?
Use xtrabackup for MySQL database physical backup
The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
随机推荐
基于Pytorch的LSTM实战160万条评论情感分类
MySQL25-索引的创建与设计原则
① BOKE
实现微信公众号H5消息推送的超级详细步骤
MySQL combat optimization expert 10 production experience: how to deploy visual reporting system for database monitoring system?
MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
【C语言】深度剖析数据存储的底层原理
该不会还有人不懂用C语言写扫雷游戏吧
How to find the number of daffodils with simple and rough methods in C language
The underlying logical architecture of MySQL
数据库中间件_Mycat总结
用于实时端到端文本识别的自适应Bezier曲线网络
MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
好博客好资料记录链接
Mysql27 - Optimisation des index et des requêtes
MySQL31-MySQL事务日志
MySQL combat optimization expert 12 what does the memory data structure buffer pool look like?
Database middleware_ MYCAT summary
Record the first JDBC
Case identification based on pytoch pulmonary infection (using RESNET network structure)