MySQL 文本与 BLOB 与 CLOB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7071662/
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
MySQL TEXT vs BLOB vs CLOB
提问by Jake Wilson
What are the differences, advantages and disadvantages of these different data-types both from a performance standpoint as well as a usability standpoint?
从性能和可用性的角度来看,这些不同数据类型的区别、优点和缺点是什么?
回答by Baseer
TEXT is a data-type for text based input. On the other hand, you have BLOB and CLOB which are more suitable for data storage (images, etc) due to their larger capacity limits (4GB for example).
TEXT 是基于文本输入的数据类型。另一方面,您有 BLOB 和 CLOB,它们更适合数据存储(图像等),因为它们具有更大的容量限制(例如 4GB)。
As for the difference between BLOB and CLOB, I believe CLOB has character encoding associated with it, which implies it can be suited well for very large amounts of text.
至于 BLOB 和 CLOB 的区别,我相信 CLOB 有与之相关的字符编码,这意味着它可以很好地适用于非常大量的文本。
BLOB and CLOB data can take a long time to retrieve, relative to how quick data from a TEXT field can be retrieved. So, use only what you need.
BLOB 和 CLOB 数据可能需要很长时间才能检索,这与检索 TEXT 字段中的数据的速度有关。所以,只使用你需要的。
回答by Jonathan L
It's worth to mention that CLOB / BLOB data types and their sizes are supported by MySQL 5.0+, so you can choose the proper data type for your need.
值得一提的是,MySQL 5.0+ 支持 CLOB / BLOB 数据类型及其大小,因此您可以根据需要选择合适的数据类型。
http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html
http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html
Data Type Date Type Storage Required
(CLOB) (BLOB)
TINYTEXT TINYBLOB L + 1 bytes, where L < 2**8 (255)
TEXT BLOB L + 2 bytes, where L < 2**16 (64 K)
MEDIUMTEXT MEDIUMBLOB L + 3 bytes, where L < 2**24 (16 MB)
LONGTEXT LONGBLOB L + 4 bytes, where L < 2**32 (4 GB)
where L stands for the byte length of a string