当前位置:网站首页>MySQL blob and text types
MySQL blob and text types
2022-06-12 15:44:00 【AlbenXie】
One 、 Basic concepts
1.Text type ( Large text series )===>>VARCHAR The enhancement of
TINYTEXT: 255 Bytes TEXT: 65535 byte
MEDIUMTEXT: 16M LONGTEXT: 4G
2.Blob type ( Large binary series )===>>BINARY The enhancement of
TINYBLOB: 255 Bytes BLOB: 65535 byte
MEDIUMBLOB: 16M LONGBLOB: 4G
3. Respectively corresponding java Types and their applications
① Store a novel or text Type of document , Consider using TEXT series . TEXT The series corresponds to Java Medium String type . Just put VARCHAR Change to TEXT system Column that will do ,Java The code doesn't need to be changed .
② Binary type , Mainly used to store images , Audio , Video and other secondary data . General , During development, we will not save binary data to the database , Instead, save the binary file in the database , Then find the file through the path .
Two 、 The main difference
1、 The main difference
TEXT And BLOB The main difference is BLOB Save binary data ,TEXT Save character data . At present, almost all the images in the blog content are not stored in the database in binary , Instead, upload the image to the server and use it in the text <img> Label reference , Such a blog can be used TEXT type . and BLOB You can convert the image into binary and save it in the database .
2、 Type difference
BLOB Yes 4 Types :TINYBLOB、BLOB、MEDIUMBLOB and LONGBLOB. They just have different maximum length of accommodation values .
TEXT Also have 4 Types :TINYTEXT、TEXT、MEDIUMTEXT and LONGTEXT. These types are the same BLOB Same type , Same maximum length and storage requirements .
3、 Character set
BLOB Column has no character set , And sort and compare numeric values based on column value bytes .TEXT Column has a character set , And sort and compare the values according to the proofreading rules of the character set
4、 Case write
stay TEXT or BLOB Column storage or retrieval process , There is no case conversion , Are all the same !
5、 Strict mode
Running in non strict mode , If you are BLOB or TEXT Column assigns a value that exceeds the maximum length of the column type , The value is truncated to ensure that it is suitable for . If the truncated character is not a space , There will be a warning . Use strictly SQL Pattern , There will be mistakes , And the value will be rejected instead of intercepted and given a warning .
6、 Other
When saving or retrieving BLOB and TEXT The value of the column does not delete trailing spaces .
about BLOB and TEXT Column index , You must specify the length of the index prefix .
BLOB and TEXT Column cannot have default value .
Only the first... Of the column is used when sorting max_sort_length Bytes .max_sort_length Of The default value is 1024.
When you want to make more than max_sort_length It's meaningful , For those with long values BLOB or TEXT Column usage GROUP BY or ORDER BY Another way to do this is to convert column values to fixed length objects . The standard method is to use SUBSTRING function .
BLOB or TEXT The maximum size of an object is determined by its type , But the maximum value that can actually be passed between the client and the server is determined by the amount of memory available and the size of the communication cache . You can change max_allowed_packet The value of the variable changes the size of the message cache , But you have to modify both the server and the client .
3、 ... and 、 Use with caution
BLOB And TEXT It's a data type designed to store huge strings , Binary and string storage .mysql These two types can be described as painstaking ,mysql These two types of values will be treated as a separate object , The storage engine usually does special processing during storage ,
When BLOB And TEXT When the value of is too large ,InnoDB Will use special “ external ” Storage area to store , In this case, each value will be taken as 1~4 A self storing pointer , Store the actual value in the external storage area .
Mysql Yes BLOB And TEXT Type is different from other types in sorting , Only for the first max_sort_length Sort by yourself , If you only need to sort the first few bytes , Then you can set max_sort_length Parameters or substring(value,length) To intercept part of the string .
These two types should be used with caution in practice , Especially when temporary tables are created , Because if the temporary table size exceeds max_heap_table_size perhaps tmp_table_size, The temporary table will be stored on disk , This leads to a decrease in the overall speed !
边栏推荐
- Web UI automation test
- What is JUC in high concurrency programming
- Deepin20.6 RTX3080 安装显卡驱动510.60.02、CUDA11.6、PyTorch1.11
- ARM 64指令小记
- Summary of advantages and disadvantages of various architectures
- Dongmingzhu talks about batteries: the most essential thing is safety
- UE4 常用类型转换
- Village to village communication (and collective search)
- Solutions to some problems of scuacm22 retreat competition before summer training
- sql server 2008 的导入导出步骤
猜你喜欢

Servlet知识详解(2)

org. xml. sax. SAXParseException; lineNumber: 63; columnNumber: 10; The definition of "mapper" in the related type must be matched with "(CAC

Deepin20.6 RTX3080 安裝顯卡驅動510.60.02、CUDA11.6、PyTorch1.11

Apache kylin Adventure

Great God cracked the AMD k6-2+ processor 22 years ago and opened the hidden 128KB L2 cache

Servlet connects to database to realize user login function

广播和多播(TCP/IP详解卷1/2)

C语言 分割bin文件程序

C language partition bin file program

从斐波那契数列求和想到的俗手、本手和妙手
随机推荐
华为设备配置CE双归属
RARP总结(TCP/IP详解卷1/2)
Remote control of other computers -- detailed tutorial
【架构优化过程思考】如何构建技术方案影响的评估能力
The difference between TCP and UDP, the three handshakes of TCP and the four waves of TCP
虚拟机中用户和root忘记密码解决办法
Notes on ARM 64 instructions
Apache Kylin 历险记
Summary of advantages and disadvantages of various architectures
Method reference instance method reference
C语言 分割bin文件程序
TS 22.011
Rust tip - running the tensorrt model through FFI programming
Servlet连接数据库实现用户登录功能
Job submission instructions upload jobs to network disk
mysql Blob和Text类型
Conversion between sparse array and array and file reading and writing
Deepin20.6 rtx3080 installer le lecteur de carte graphique 510.60.02, cuda 11.6, pytorch1.11
广播和多播(TCP/IP详解卷1/2)
鼻孔插灯,智商上升,风靡硅谷,3万就成