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);

[root@mydb ~]# 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章