前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >TINYTEXT,TEXT,MEDIUMTEXT和LONGTEXT最大存储容量

TINYTEXT,TEXT,MEDIUMTEXT和LONGTEXT最大存储容量

作者头像
全栈程序员站长
发布2022-09-21 17:37:45
9360
发布2022-09-21 17:37:45
举报

大家好,又见面了,我是你们的朋友全栈君。

本文翻译自: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 : 文档

代码语言:javascript
复制
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 . 需要注意的是,可以存储在列中的字符数将取决于字符编码


#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

代码语言:javascript
复制
      Type | A= worst case (x/3) | B = best case (x) | words estimate (A/4.5) - (B/4.5)
-----------+---------------------------------------------------------------------------
  TINYTEXT |              85     | 255               | 18 - 56
      TEXT |          21,845     | 65,535            | 4,854.44 - 14,563.33  
MEDIUMTEXT |       5,592,415     | 16,777,215        | 1,242,758.8 - 3,728,270
  LONGTEXT |   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的挑战,这是我可以存储在话测量的每个文本类型的最大长度的估计:

代码语言:javascript
复制
      Type |         Bytes | English words | Multi-byte words
-----------+---------------+---------------+-----------------
  TINYTEXT |           255 |           ±44 |              ±23
      TEXT |        65,535 |       ±11,000 |           ±5,900
MEDIUMTEXT |    16,777,215 |    ±2,800,000 |       ±1,500,000
  LONGTEXT | 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. 存在性能开销,但确实有用。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/170354.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • #1楼
  • #2楼
  • #3楼
  • #4楼
  • #5楼
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档