当前位置:网站首页>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 .
边栏推荐
- Use xtrabackup for MySQL database physical backup
- 软件测试工程师发展规划路线
- How to build an interface automation testing framework?
- Mysql24 index data structure
- MySQL实战优化高手05 生产经验:真实生产环境下的数据库机器配置如何规划?
- Google login prompt error code 12501
- A necessary soft skill for Software Test Engineers: structured thinking
- 数据库中间件_Mycat总结
- MySQL combat optimization expert 12 what does the memory data structure buffer pool look like?
- MySQL combat optimization expert 10 production experience: how to deploy visual reporting system for database monitoring system?
猜你喜欢

Just remember Balabala

If someone asks you about the consistency of database cache, send this article directly to him

MySQL实战优化高手03 用一次数据更新流程,初步了解InnoDB存储引擎的架构设计

MySQL combat optimization expert 03 uses a data update process to preliminarily understand the architecture design of InnoDB storage engine
![13 medical registration system_ [wechat login]](/img/c9/05ad1fc86e02cf51a37c9331938b0a.jpg)
13 medical registration system_ [wechat login]

MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?

Security design verification of API interface: ticket, signature, timestamp

MySQL的存储引擎

In fact, the implementation of current limiting is not complicated

Mysql34 other database logs
随机推荐
第一篇博客
PyTorch RNN 实战案例_MNIST手写字体识别
[Julia] exit notes - Serial
ZABBIX introduction and installation
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
Adaptive Bezier curve network for real-time end-to-end text recognition
① BOKE
Google login prompt error code 12501
MySQL combat optimization expert 04 uses the execution process of update statements in the InnoDB storage engine to talk about what binlog is?
保姆级手把手教你用C语言写三子棋
15 medical registration system_ [appointment registration]
Mysql27 index optimization and query optimization
Implement context manager through with
A necessary soft skill for Software Test Engineers: structured thinking
Nanny hand-in-hand teaches you to write Gobang in C language
How to build an interface automation testing framework?
Ueeditor internationalization configuration, supporting Chinese and English switching
Security design verification of API interface: ticket, signature, timestamp
MySQL28-数据库的设计规范
该不会还有人不懂用C语言写扫雷游戏吧