mysql关于表空间的总结

出处:http://blog.itpub.net/30126024/viewspace-2216262/

1.系统表空间(System Tablespace)

innodb系统表空间包含innodb数据字典(innodb相关对象的元数据),undo logs、the change buffer, and the doublewrite buffer。

此外,当innodb_file_per_table=OFF时系统表空间也存储表空间创建的表和索引等数据。

由于系统表空间可以存储多张表,因此,其为一个共享表空间。

系统表空间由一个或多个数据文件组成,默认情况下,其包含一个叫ibdata1的系统数据文件,位于mysql数据目录下。

系统表空间数据文件的大小和数目由innodb_data_file_path启动选项控制。

 

innodb_data_file_path=ibdata1:50M;ibdata2:12M:autoextend:max:500MB

多个文件的情况下, 实际存在的文件的大小必须和物理大小一样,如上ibdata1的大小50M必须和实际存储大小一样

autoextend和max属性只能用于innodb_data_file_path设置中最后指定的数据文件

 

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.

Prior to MySQL 5.6.7, the default was to keep all InnoDB tables and indexes inside the system tablespace, often causing this file to become very large. Because the system tablespace never shrinks, storage problems could arise if large amounts of temporary data were loaded and then deleted. In MySQL 5.7, the default is file-per-table mode, where each table and its associated indexes are stored in a separate .ibd file. 

包含InnoDB相关对象(InnoDB数据字典)的元数据的一个或多个数据文件(ibdata文件),以及更改缓冲区,双写缓冲区和可能的撤消日志的存储区域。 如果在系统表空间而不是每个表文件或一般表空间中创建表,它还可能包含InnoDB表的表和索引数据。 系统表空间中的数据和元数据适用于MySQL实例中的所有数据库。

在MySQL 5.6.7之前,默认设置是将所有InnoDB表和索引保留在系统表空间内,这通常会导致此文件变得非常大。 由于系统表空间永远不会缩小,因此如果加载并删除了大量临时数据,则可能会出现存储问题。 在MySQL 5.7中,默认为每表文件模式,其中每个表及其相关索引存储在单独的.ibd文件中。

 

 

2.表文件表空间(File-Per-Table Tablespaces)

表文件表空间是一个单表表空间,该表创建于自己的数据文件中。当innodb_file_per_table选项开启时,表将被创建于表文件表空间中。

保存单个InnoDB表数据的每表文件表空间由.ibd数据文件表示

https://dev.mysql.com/doc/refman/5.7/en/innodb-multiple-tablespaces.html

Historically, all InnoDB tables and indexes were stored in the system tablespace. This monolithic approach was targeted at machines dedicated entirely to database processing, with carefully planned data growth, where any disk storage allocated to MySQL would never be needed for other purposes. InnoDB's file-per-table tablespace feature provides a more flexible alternative, where each InnoDB table and its indexes are stored in a separate .ibd data file. Each such .ibd data file represents an individual tablespace. This feature is controlled by the innodb_file_per_table configuration option, which is enabled by default in MySQL 5.6.6 and higher.

从历史上看,所有InnoDB表和索引都存储在系统表空间中。 这种单片方法的目标是完全专用于数据库处理的机器,精心规划的数据增长,其中任何分配给MySQL的磁盘存储都不会用于其他目的。 InnoDB的每表文件表空间功能提供了更灵活的替代方案,其中每个InnoDB表及其索引都存储在单独的.ibd数据文件中。 每个这样的.ibd数据文件代表一个单独的表空间。 此功能由innodb_file_per_table配置选项控制,该选项在MySQL 5.6.6及更高版本中默认启用。

 

 

3.通用表空间(General Tablespaces)

https://dev.mysql.com/doc/refman/5.7/en/general-tablespaces.html

A general tablespace is a shared InnoDB tablespace that is created using CREATE TABLESPACE syntax

通用表空间是使用CREATE TABLESPACE语法创建的共享InnoDB表空间

Creating a general tablespace in the MySQL data directory 在MySQL数据目录中创建通用表空间:

mysql> CREATE TABLESPACE `ts1` ADD DATAFILE 'ts1.ibd' Engine=InnoDB;

Creating a general tablespace in a directory outside of the MySQL data directory 在MySQL数据目录之外的目录中创建通用表空间:

mysql> CREATE TABLESPACE `ts1` ADD DATAFILE '/my/tablespace/directory/ts1.ibd' Engine=InnoDB;

mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts1;

mysql> ALTER TABLE t2 TABLESPACE ts1;

 

 

4.undo表空间(undo tablespace)

https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_undo_tablespaces

innodb_undo_tablespaces is deprecated and will be removed in a future release.

5.7.21版本开始innodb_undo_tablespaces已弃用,将在以后的版本中删除

 

 

5.临时表空间(Temporary Tablespace)

https://dev.mysql.com/doc/refman/5.7/en/innodb-temporary-tablespace.html

Non-compressed, user-created temporary tables and on-disk internal temporary tables are created in a shared temporary tablespace

The innodb_temp_data_file_path configuration option defines the relative path, name, size, and attributes for temporary tablespace data files. If no value is specified for innodb_temp_data_file_path, the default behavior is to create an auto-extending data file named ibtmp1 in the innodb_data_home_dir directory that is slightly larger than 12MB.

Compressed temporary tables, which are temporary tables created using the ROW_FORMAT=COMPRESSED attribute, are created in file-per-table tablespaces in the temporary file directory.

The temporary tablespace is removed on normal shutdown or on an aborted initialization, and is recreated each time the server is started . The temporary tablespace receives a dynamically generated space ID when it is created. Startup is refused if the temporary tablespace cannot be created. The temporary tablespace is not removed if the server halts unexpectedly. In this case, a database administrator can remove the temporary tablespace manually or restart the server, which removes and recreates the temporary tablespace automatically.

压缩临时表是使用ROW_FORMAT = COMPRESSED属性创建的临时表,它们是在临时文件目录中的每表文件表空间中创建的。

用户创建的临时表和磁盘内部临时表创建于共享临时表空间中。

innodb_temp_data_file_path配置选项定义临时表空间数据文件的相对路径,名称,大小和属性。 如果没有为innodb_temp_data_file_path指定值,则默认行为是在innodb_data_home_dir目录中创建一个稍大于12MB的名为 ibtmp1 的自动扩展数据文件。

临时表空间在正常关闭或中止初始化时被删除,并在每次启动服务器时重新创建 。 临时表空间在创建时会收到动态生成的空间ID。 如果无法创建临时表空间,则拒绝启动。 如果服务器意外停止,则不会删除临时表空间。 在这种情况下,数据库管理员可以手动删除临时表空间或重新启动服务器,从而自动删除并重新创建临时表空间。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30126024/viewspace-2216262/,如需转载,请注明出处,否则将追究法律责任。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值