本文翻译自:TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT maximum storage sizes

Per the MySQL docs , there are four TEXT types: 根据MySQL文档 ,有四种TEXT类型:

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

What is the maximum length that I can store in a column of each data type assuming the character encoding is UTF-8? 假设字符编码为UTF-8,我可以在每种数据类型的列中存储的最大长度是多少?


#1楼

参考:https://stackoom.com/question/wSXm/TINYTEXT-TEXT-MEDIUMTEXT和LONGTEXT最大存储容量


#2楼

From the documentation : 从文档 :

Type | Maximum length
-----------+-------------------------------------TINYTEXT |           255 (2 8−1) bytesTEXT |        65,535 (216−1) bytes = 64 KiB
MEDIUMTEXT |    16,777,215 (224−1) bytes = 16 MiBLONGTEXT | 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 . 需要注意的是,可以存储在列中的字符数将取决于字符编码


#3楼

Expansion of the same answer 扩展相同的答案

  1. This SO post outlines in detail the overheads and storage mechanisms. 这篇SO帖子详细列出了开销和存储机制。
  2. As noted from point (1), A VARCHAR should always be used instead of TINYTEXT. 如第(1)点所述,应始终使用A VARCHAR而不是TINYTEXT。 However, when using VARCHAR, the max rowsize should not exceeed 65535 bytes. 但是,使用VARCHAR时,max rowsize不应超过65535字节。
  3. As outlined here http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-utf8.html , max 3 bytes for utf-8. 如http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-utf8.html所述 ,utf-8最多3个字节。

THIS IS A ROUGH ESTIMATION TABLE FOR QUICK DECISIONS! 这是一个用于快速决策的粗略估计表!

  1. So the worst case assumptions (3 bytes per utf-8 char) to best case (1 byte per utf-8 char) 所以最坏的情况假设(每个utf-8字符3个字节)到最佳情况(每个utf-8字符1个字节)
  2. Assuming the english language has an average of 4.5 letters per word 假设英语每个单词平均有4.5个字母
  3. x is the number of bytes allocated x是分配的字节数

xx XX

      Type | A= worst case (x/3) | B = best case (x) | words estimate (A/4.5) - (B/4.5)
-----------+---------------------------------------------------------------------------TINYTEXT |              85     | 255               | 18 - 56TEXT |          21,845     | 65,535            | 4,854.44 - 14,563.33
MEDIUMTEXT |       5,592,415     | 16,777,215        | 1,242,758.8 - 3,728,270LONGTEXT |   1,431,655,765     | 4,294,967,295     | 318,145,725.5 - 954,437,176.6

Please refer to Chris V's answer as well : https://stackoverflow.com/a/35785869/1881812 请参阅Chris V的答案: https : //stackoverflow.com/a/35785869/1881812


#4楼

Rising to @Ankan-Zerob's challenge, this is my estimate of the maximum length which can be stored in each text type measured in words : 上升到@俺看-Zerob的挑战,这是我可以存储在话测量的每个文本类型的最大长度的估计:

      Type |         Bytes | English words | Multi-byte words
-----------+---------------+---------------+-----------------TINYTEXT |           255 |           ±44 |              ±23TEXT |        65,535 |       ±11,000 |           ±5,900
MEDIUMTEXT |    16,777,215 |    ±2,800,000 |       ±1,500,000LONGTEXT | 4,294,967,295 |  ±740,000,000 |     ±380,000,000

In English , 4.8 letters per word is probably a good average (eg norvig.com/mayzner.html ), though word lengths will vary according to domain (eg spoken language vs. academic papers), so there's no point being too precise. 英语中 ,每个单词4.8个字母可能是一个很好的平均值(例如norvig.com/mayzner.html ),尽管单词长度会根据域名(例如口语与学术论文)而有所不同,因此没有必要过于精确。 English is mostly single-byte ASCII characters, with very occasional multi-byte characters, so close to one-byte-per-letter. 英语主要是单字节ASCII字符,偶尔有多字节字符,因此接近每字节一个字节。 An extra character has to be allowed for inter-word spaces, so I've rounded down from 5.8 bytes per word. 字间空间必须有一个额外的字符,所以我从每个字的5.8个字节向下舍入。 Languages with lots of accents such as say Polish would store slightly fewer words, as would eg German with longer words. 有很多口音的语言,例如说波兰语,会存储稍微少一些的单词,例如德语,单词较长。

Languages requiring multi-byte characters such as Greek, Arabic, Hebrew, Hindi, Thai, etc, etc typically require two bytes per character in UTF-8. 需要多字节字符的语言,如希腊语,阿拉伯语,希伯来语,印地语,泰语等,通常需要UTF-8中每个字符两个字节。 Guessing wildly at 5 letters per word, I've rounded down from 11 bytes per word. 每个单词5个字母疯狂地猜测,我从每个单词的11个字节向下舍入。

CJK scripts (Hanzi, Kanji, Hiragana, Katakana, etc) I know nothing of; CJK剧本(汉字,汉字,平假名,片假名等)我一无所知; I believe characters mostly require 3 bytes in UTF-8, and (with massive simplification) they might be considered to use around 2 characters per word, so they would be somewhere between the other two. 我认为字符大多需要UTF-8中的3个字节,并且(大量简化)它们可能被认为每个字使用大约2个字符,所以它们将介于其他两个字符之间。 (CJK scripts are likely to require less storage using UTF-16, depending). (CJK脚本可能需要使用UTF-16来减少存储,具体取决于)。

This is of course ignoring storage overheads etc. 这当然忽略了存储开销等。


#5楼

This is nice but doesn't answer the question: 这很好,但没有回答这个问题:

"A VARCHAR should always be used instead of TINYTEXT." “应始终使用VARCHAR而不是TINYTEXT。” Tinytext is useful if you have wide rows - since the data is stored off the record. 如果你有宽行,Tinytext很有用 - 因为数据存储在记录之外。 There is a performance overhead, but it does have a use. 存在性能开销,但确实有用。

TINYTEXT,TEXT,MEDIUMTEXT和LONGTEXT最大存储容量相关推荐

  1. TEXT、TINYTEXT、MEDIUMTEXT、LONGTEXT选择 和 char varchar varchar2 的区别

    TEXT.TINYTEXT.MEDIUMTEXT.LONGTEXT的区别: 储存不区分大小写的字符数据 TINYTEXT 最大长度是 255 (2^8 - 1) 个字符. TEXT 最大长度是 655 ...

  2. mysql longtext查询_MySQL中TEXT、TINYTEXT、MEDIUMTEXT、LONGTEXT选择

    储存不区分大小写的字符数据 TINYTEXT 最大长度是 255 (2^8 – 1) 个字符. TEXT 最大长度是 65535 (2^16 – 1) 个字符. MEDIUMTEXT 最大长度是 16 ...

  3. TEXT、TINYTEXT、MEDIUMTEXT、LONGTEXT选择

    储存不区分大小写的字符数据 TINYTEXT 最大长度是 255 (2^8 - 1) 个字符. TEXT 最大长度是 65535 (2^16 - 1) 个字符. MEDIUMTEXT 最大长度是 16 ...

  4. mysql的text与tinytext_MySQL中tinytext、text、mediumtext和longtext等各个类型详解

    今天有个小伙伴在群里问text为什么长度是0,会不会影响存数据失败,这里就有各个类型的详细说明 TEXT.TINYTEXT.MEDIUMTEXT.LONGTEXT的区别: 储存不区分大小写的字符数据 ...

  5. mediumtext_MySQL中tinytext、text、mediumtext和longtext等各个类型详解

    今天有个小伙伴在群里问text为什么长度是0,会不会影响存数据失败,这里就有各个类型的详细说明 TEXT.TINYTEXT.MEDIUMTEXT.LONGTEXT的区别: 储存不区分大小写的字符数据 ...

  6. mediumtext_MySQL中tinytext、text、mediumtext和longtext等各个类型详解【图】

    MySQL中tinytext.text.mediumtext和longtext等各个类型详解[图] 07-29栏目:技术 TAG:mediumtext mediumtext 一.字符串类型 www.j ...

  7. MySQL中tinytext、text、mediumtext和longtext等类型详解

    一.数字类型 类型 范围 说明 Char(N) [ binary] N=1~255 个字元 binary :分辨大小写 固定长度 std_name cahr(32) not null VarChar( ...

  8. MySQL中tinytext、text、mediumtext和longtext详解

    转载自:https://www.cnblogs.com/pureEve/p/6015000.html 一.数字类型 类型 范围 说明   Char(N) [binary] N=1~255 个字元 bi ...

  9. mysql mediumtext 最大_mysql - TINYTEXT,TEXT,MEDIUMTEXT和LONGTEXT最大存储大小

    上升到@ Ankan-Zerob的挑战,这是我对每个文本类型中可以存储的最大长度的估计: Type | Bytes | English words | Multi-byte words ------- ...

最新文章

  1. 荣耀mgaic2鸿蒙系统,华为没有抛弃荣耀!我看着当年4400买的荣耀Magic2,不争气地哭了...
  2. 彻底解决IAR中Go to definition of不可用
  3. spring:《spring实战》读后感二
  4. qt 在点击菜单下的动作之后获取该菜单的名称
  5. WebAdaptor Object reference not set to an instance of an object.
  6. TFS2010配置SQLServer2008R2 tf255049错误
  7. 广播 BroadCastReceiver
  8. 当鼠标移入时切换背景图时闪烁的问题
  9. rpcbind服务说明及关闭
  10. 使用Sophix热修复注意事项
  11. 个人简单版租房合同范本电子版Word模板免费下载样板
  12. R语言--(8)--描述统计量
  13. session自动登录抽屉网(自动携带cookie)
  14. zoj3551 Bloodsucker//概率dp
  15. Stream实践总结
  16. Prime Number
  17. 谢惠民,恽自求,易法槐,钱定边编数学分析习题课讲义23.2.3练习题参考解答[来自陶哲轩小弟]...
  18. PHP批量下载远程文件到本地
  19. 寒冬之下持续吸金,蛰伏30年的国产数据库终迎黄金时代?
  20. 力天创见客流工程实施

热门文章

  1. java熔断_Hystrix熔断机制原理剖析
  2. 鸿蒙应用开发 | 选项卡(TabList / Tab)的功能和用法
  3. 铁威马NAS忘记密码找回方式
  4. elasticsearch报错: illegal argument exception, variable is not found
  5. php show.bs.popover,bootstrap popover用法和popover中文api
  6. 好玩的-记最近玩的几个经典ipad ios游戏
  7. vue绑定键盘事件 ctrl+enter触发事件
  8. 微信小程序模仿开眼视频app(三)——信息卡片瀑布流和分类
  9. Cisco默认网关远程登录
  10. iOS 客户端接口报错信息处理(未能完成该操作。软件导致连接中止 或者是 Software caused connection abort Code 53)