MySQL 中的 BLOB 和 TEXT 数据类型有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11624807/
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
What are the differences between the BLOB and TEXT datatypes in MySQL?
提问by nencor
What is blob
and what is text
? What are the differences?
什么是blob
什么text
?有什么区别?
When do I need to use blob
and when do I need text
as data type?
我什么时候需要使用blob
,什么时候需要text
作为数据类型?
Because for blob
and text
, there are mediumblob
== mediumtext
, smallblob
== small text
. Do they even have the same meaning?
因为对于blob
and text
,有mediumblob
== mediumtext
, smallblob
== small text
。它们甚至具有相同的含义吗?
And look at this MEDIUMBLOB
, MEDIUMTEXT L
+ 3 bytes, where L < 224
.
看看这个MEDIUMBLOB
, MEDIUMTEXT L
+ 3 个字节,其中L < 224
.
What is L
?
什么是L
?
采纳答案by Darcey
TEXT and CHAR will convert to/from the character set they have associated with time. BLOB and BINARY simply store bytes.
TEXT 和 CHAR 将转换为/从它们与时间关联的字符集。BLOB 和 BINARY 只是存储字节。
BLOB is used for storing binary data while Text is used to store large string.
BLOB 用于存储二进制数据,而 Text 用于存储大字符串。
BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values.
BLOB 值被视为二进制字符串(字节字符串)。它们没有字符集,排序和比较是基于列值中字节的数值。
TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set.
TEXT 值被视为非二进制字符串(字符串)。它们有一个字符集,并根据字符集的排序规则对值进行排序和比较。
回答by COLD TOLD
TEXT and CHAR or nchar that will typically be converted to plain text so you can only store text like strings.
TEXT 和 CHAR 或 nchar 通常会转换为纯文本,因此您只能存储像字符串一样的文本。
BLOB and BINARY which mean you can store binary data such as images simply store bytes.
BLOB 和 BINARY 这意味着您可以存储二进制数据,例如图像,只需存储字节。
回答by Kenny
Blob datatypes stores binary objects like images while text datatypes stores text objects like articles of webpages
Blob 数据类型存储二进制对象,如图像,而文本数据类型存储文本对象,如网页文章
回答by James Williams
A BLOB is a binary string to hold a variable amount of data. For the most part BLOB's are used to hold the actual image binary instead of the path and file info. Text is for large amounts of string characters. Normally a blog or news article would constitute to a TEXT field
BLOB 是一个二进制字符串,用于保存可变数量的数据。大多数情况下,BLOB 用于保存实际的图像二进制文件,而不是路径和文件信息。文本用于大量字符串字符。通常,博客或新闻文章将构成 TEXT 字段
L in this case is used stating the storage requirement. (Length|Size + 3) as long as it is less than 224.
在这种情况下,L 用于说明存储要求。(Length|Size + 3) 只要小于 224。
回答by Alireza Rahmani Khalili
According to High-performance Mysql book:
根据高性能 Mysql 书:
The only difference between the BLOBand TEXTfamilies is that BLOBtypes store binary data with no collation or character set, but TEXTtypes have a character set and collation.
BLOB和TEXT系列之间的唯一区别是BLOB类型存储没有排序规则或字符集的二进制数据,但TEXT类型具有字符集和排序规则。
回答by Abhishek Saha
BLOB stores binary data which are more than 2 GB. Max size for BLOB is 4 GB. Binary data means unstructured data i.e images audio files vedio files digital signature
BLOB 存储超过 2 GB 的二进制数据。BLOB 的最大大小为 4 GB。二进制数据是指非结构化数据,即图像、音频文件、视频文件、数字签名
Text is used to store large string.
文本用于存储大字符串。