TINYTEXT、TEXT、MEDIUMTEXT 和 LONGTEXT 最大存储大小

2021-11-20 00:00:00 mysql innodb

根据 MySQL 文档,有四种 TEXT 类型:

  1. TINYTEXT
  2. 文本
  3. 中文本
  4. 长文本

假设字符编码为 UTF-8,我可以在每种数据类型的列中存储的最大长度是多少?

解决方案

来自 文档 (MySQL 8) :

<前>类型 |最大长度-----------+------------------------------------小文字 |255 (2 8−1) 字节正文 |65,535 (216−1) 字节 = 64 KiB中文本 |16,777,215 (224−1) 字节 = 16 MiB长文 |4,294,967,295 (232−1) 字节 = 4 GiB

请注意,列中可以存储的字符数量取决于字符编码.

Per the MySQL docs, there are four TEXT types:

  1. TINYTEXT
  2. TEXT
  3. MEDIUMTEXT
  4. LONGTEXT

What is the maximum length that I can store in a column of each data type assuming the character encoding is UTF-8?

解决方案

From the documentation (MySQL 8) :

      Type | Maximum length
-----------+-------------------------------------
  TINYTEXT |           255 (2 8−1) bytes
      TEXT |        65,535 (216−1) bytes = 64 KiB
MEDIUMTEXT |    16,777,215 (224−1) bytes = 16 MiB
  LONGTEXT | 4,294,967,295 (232−1) bytes =  4 GiB

Note that the number of characters that can be stored in your column will depend on the character encoding.

相关文章