首页
学习
活动
专区
工具
TVP
发布

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

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20181006A1HH5W00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券