MySQL - TEXT 与 CHAR 和 VARCHAR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2083791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:00:32  来源:igfitidea点击:

MySQL - TEXT vs CHAR and VARCHAR

mysqltexttypescharvarchar

提问by Alix Axel

Reading this question, a doubt popped into my head:

看到这个问题,我的脑子里冒出一个疑问:

  • char and varchar can store up to 255 chars
  • text can store up to 65k chars
  • char size in bytes is number of chars
  • varchar size in bytes is number of chars used+ 1
  • char 和 varchar 最多可以存储 255 个字符
  • 文本最多可存储 65k 个字符
  • 以字节为单位的字符大小是字符数
  • 以字节为单位的 varchar 大小是使用的字符数+ 1

So how much bytes does TEXT actually occupy? ~65KB or number of chars used+ 1?

那么TEXT实际占用了多少字节呢?~65KB 或使用的字符数+ 1?

采纳答案by Pindatjuh

TEXT is a variable length datatype, with a maximum of 65,000 characters.

TEXT 是可变长度数据类型,最多 65,000 个字符。

LONGTEXT can be used for over 4 trillion characters.

LONGTEXT 可用于超过 4 万亿个字符。

To answer your question: it's a variable lenght, and it will only occupy the amount of characters you store.

回答你的问题:它是一个可变长度,它只会占用你存储的字符数。

回答by Aleksandr

TEXT occupies a number actual length of your data + 2 bytes.

TEXT 占用数据的实际长度 + 2 个字节。