Skip to content
Zhang Jc edited this page Mar 29, 2017 · 8 revisions

MySQL(InnoDB)的存储机制

1. MySQL的BLOB类型和TEXT类型

(摘自官方docs)

A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements.

(摘自百度百科)

BLOB (binary large object),二进制大对象,是一个可以存储二进制文件的容器。 在计算机中,BLOB常常是数据库中用来存储二进制文件的字段类型。 BLOB是一个大文件,典型的BLOB是一张图片或一个声音文件,由于它们的尺寸,必须使用特殊的方式来处理(例如:上传、下载或者存放到一个数据库)。 根据Eric Raymond的说法,处理BLOB的主要思想就是让文件处理器(如数据库管理器)不去理会文件是什么,而是关心如何去处理它。 但也有专家强调,这种处理大数据对象的方法是把双刃剑,它有可能引发一些问题,如存储的二进制文件过大,会使数据库的性能下降。在数据库中存放体积较大的多媒体对象就是应用程序处理BLOB的典型例子。

2. 关于Mysql的页(Page)

(摘自官方docs) A unit representing how much data InnoDB transfers at any one time between disk (the data files) and memory (the buffer pool).

[MySQL5.7 文档]

The default page size in InnoDB is 16KB. You can increase or decrease the page size by configuring the innodb_page_size option when creating the MySQL instance.

ROW_FORMAT=COMPRESSED in the Barracuda file format assumes that the page size is at most 16KB and uses 14-bit pointers.

32KB and 64KB page sizes are supported, but ROW_FORMAT=COMPRESSED is unsupported for page sizes greater than 16KB. For both 32KB and 64KB page sizes, the maximum record size is 16KB. For innodb_page_size=32k, extent size is 2MB. For innodb_page_size=64k, extent size is 4MB.

A MySQL instance using a particular InnoDB page size cannot use data files or log files from an instance that uses a different page size.

[MySQL5.5 文档] The default page size in InnoDB is 16KB.

Changing the page size is not a supported operation and there is no guarantee that InnoDB functions normally with a page size other than 16KB. Problems compiling or running InnoDB may occur. In particular, ROW_FORMAT=COMPRESSED in the Barracuda file format assumes that the page size is at most 16KB and uses 14-bit pointers.

A version of InnoDB built for one page size cannot use data files or log files from a version built for a different page size. This limitation could affect restore or downgrade operations using data from MySQL 5.6, which does support page sizes other than 16KB.

  • MySQK 5.5.37源码中,可以看到页大小为16kb

storage/innobase/include/univ.i中:

/* The 2-logarithm of UNIV_PAGE_SIZE: */
#define UNIV_PAGE_SIZE_SHIFT	14
/* The universal page size of the database */
#define UNIV_PAGE_SIZE		(1 << UNIV_PAGE_SIZE_SHIFT)
  • MySQK 5.7.17源码中,可以看到页大小不再是一个常量了,16K还是默认大小

storage/innobase/srv/srv0srv.cc中:

ulong		srv_page_size = UNIV_PAGE_SIZE_DEF;

storage/innobase/include/univ.i中:

#define UNIV_PAGE_SIZE_SHIFT_DEF	14
#define UNIV_PAGE_SIZE_DEF	(1 << UNIV_PAGE_SIZE_SHIFT_DEF)
/** The 2-logarithm of UNIV_PAGE_SIZE: */
#define UNIV_PAGE_SIZE_SHIFT	srv_page_size_shift
/** The universal page size of the database */
#define UNIV_PAGE_SIZE		((ulint) srv_page_size)

3. 行式数据库和列式数据库

传统的数据库都是按行存储的行式数据库,新兴的列式数据库按列存储,这样可以增大压缩比,增加空间利用效率。行式数据库适合OLTP,列式数据库适合OLAP。

4. OLTP和OLAP

(摘自百度知道)

OLTP即联机事务处理,就是我们经常说的关系数据库,意即记录即时的增、删、改、查,就是我们经常应用的东西,这是数据库的基础;

OLAP即联机分析处理,是数据仓库的核心部心,所谓数据仓库是对于大量已经由OLTP形成的数据的一种分析型的数据库,用于处理商业智能、决策支持等重要的决策信息;数据仓库是在数据库应用到一定程序之后而对历史数据的加工与分析;是处理两种不同用途的工具而已。

5. InnoDB数据存储流程

[细看InnoDB数据落盘] http://hatemysql.com/?tag=innodb_flush_method

6. InnoDB存储组织结构

http://hedengcheng.com/?p=118

http://www.linuxidc.com/Linux/2016-03/128827.htm

http://www.cnblogs.com/vinchen/archive/2012/09/10/2679478.html

http://www.cnblogs.com/benshan/archive/2013/01/08/2851714.html

[InnoDB源码分析] http://blog.csdn.net/column/details/innodb-zerok.html

Clone this wiki locally