1. 程式人生 > >mysql關於ibdata檔案的理解

mysql關於ibdata檔案的理解

總結

1、預設情況下ibdata存放InnoDB表(InnoDB資料字典)元資料、undo logs、the change buffer, and the doublewrite buffer

2、如果innodb_file_per_table=off,則ibdata也存放InnoDB表的實際資料,也就是InnoDB表建立後,不會再有單獨的tablename.ibd檔案

3、雖然InnoDB表元資料通過information_schema.tables來讀取,但是實際上information_schema是一個虛擬資料庫,並不物理存在,這些資料真正存放的地方就是ibdata

備註:元資料(meta data)--"data about data" 關於資料的資料,一般是結構化資料(如儲存在資料庫裡的資料,規定了欄位的長度、型別等)

ibdata file

https://dev.mysql.com/doc/refman/5.7/en/glossary.html#glos_ibdata_file

A set of files with names such as ibdata1, ibdata2, and so on, that make up the InnoDB system tablespace. These files contain metadata about InnoDB tables, (the InnoDB data dictionary), and the storage areas for one or more undo logs, the change buffer, and the doublewrite buffer. They also can contain some or all of the table data also (depending on whether the file-per-table mode is in effect when each table is created). When the innodb_file_per_table option is enabled, data and indexes for newly created tables are stored in separate .ibd files rather than in the system tablespace.

The growth of the ibdata files is influenced by the innodb_autoextend_increment configuration option

一組名稱為ibdata1,ibdata2等的檔案,構成InnoDB系統表空間。 這些檔案包含有關InnoDB表(InnoDB資料字典)的元資料,以及一個或多個撤消日誌,更改緩衝區和雙寫緩衝區的儲存區域。 它們還可以包含部分或全部表資料(取決於建立每個表時每個表的檔案模式是否有效)。 啟用innodb_file_per_table選項後,新建立的表的資料和索引將儲存在單獨的.ibd檔案中,而不是儲存在系統表空間中。

ibdata檔案的增長受innodb_autoextend_increment配置選項的影響,預設是64M

The increment size (in megabytes) for extending the size of an auto-extending InnoDB system tablespace file when it becomes full. The default value is 64

MySQL開啟獨享表空間的引數是Innodb_file_per_table,會為每個Innodb表建立一個.ibd的檔案。

開啟獨享表空間後,並不是說就不需要ibdata1了,因為在ibdata1中還儲存著下面這些資料。

InnoDB表的元資料

Buffer

UNDO日誌

system tablespace

https://dev.mysql.com/doc/refman/5.7/en/glossary.html#glos_system_tablespace

One or more data files (ibdata files) containing metadata for InnoDB-related objects (the InnoDB data dictionary), and the storage areas for the change buffer, the doublewrite buffer, and possibly undo logs. It may also contain table and index data for InnoDB tables if tables were created in the system tablespace instead of file-per-table or general tablespaces. The data and metadata in the system tablespace apply to all databases in a MySQL instance.

系統表空間

包含InnoDB相關物件(InnoDB資料字典)的元資料的一個或多個數據檔案(ibdata檔案),以及更改緩衝區,雙寫緩衝區和可能的撤消日誌的儲存區域。 如果在系統表空間而不是每個表文件或一般表空間中建立表,它還可能包含InnoDB表的表和索引資料。 系統表空間中的資料和元資料適用於MySQL例項中的所有資料庫。

實驗過程

會話1

mysql> set global innodb_file_per_table=off;

mysql> show variables like '%innodb_file_per_table%';

+-----------------------+-------+

| Variable_name | Value |

+-----------------------+-------+

| innodb_file_per_table | OFF |

+-----------------------+-------+

開啟會話2

建立了表tab4並插入資料,卻發現tab4表沒有tab4.ibd檔案

mysql> create table test1.tab4 (hid int);

mysql> insert into test1.tab4 values (1);

[[email protected] ~]# ll /var/lib/mysql/test1 |grep tab4

-rw-r----- 1 mysql mysql 8558 Sep 30 19:56 tab4.frm

最後送波福利。現在加群即可獲取Java工程化、高效能及分散式、高效能、高架構。效能調優、Spring,MyBatis,Netty原始碼分析和大資料等多個知識點高階進階乾貨的直播免費學習許可權及領取相關資料,群號:835638062 點選連結加入群聊【Java高階架構】:https://jq.qq.com/?_wv=1027&k=5S3kL3v