MySQL中TEXT与BLOB字段类型的区别_MySQL
在MySQL中有两个字段类型容易让人感觉混淆,那就是TEXT与BLOB,特别是自己写博客程序的博主不知道改为自己的博客正文字段选择TEXT还是BLOB类型。
下面给出几点区别:
一、主要差别
TEXT与BLOB的主要差别就是BLOB保存二进制数据,TEXT保存字符数据。目前几乎所有博客内容里的图片都不是以二进制存储在数据库的,而是把图片上传到服务器然后正文里使用标签引用,这样的博客就可以使用TEXT类型。而BLOB就可以把图片换算成二进制保存到数据库中。
二、类型区别
BLOB有4种类型:TINYBLOB、BLOB、MEDIUMBLOB和LONGBLOB。它们只是可容纳值的最大长度不同。
TEXT也有4种类型:TINYTEXT、TEXT、MEDIUMTEXT和LONGTEXT。这些类型同BLOB类型一样,有相同的最大长度和存储需求。
三、字符集
BLOB列没有字符集,并且排序和比较基于列值字节的数值值。TEXT列有一个字符集,并且根据字符集的校对规则对值进行排序和比较
四、大小写
在TEXT或BLOB列的存储或检索过程中,不存在大小写转换,都一样!
五、严格模式
运行在非严格模式时,如果你为BLOB或TEXT列分配一个超过该列类型的最大长度的值值,值被截取以保证适合。如果截掉的字符不是空格,将会产生一条警告。使用严格SQL模式,会产生错误,并且值将被拒绝而不是截取并给出警告。
六、其它
当保存或检索BLOB和TEXT列的值时不删除尾部空格。
对于BLOB和TEXT列的索引,必须指定索引前缀的长度。
BLOB和TEXT列不能有默认值。
当排序时只使用该列的前max_sort_length个字节。max_sort_length的 默认值是1024。
当你想要使超过max_sort_length的字节有意义,对含长值的BLOB或TEXT列使用GROUP BY或ORDER BY的另一种方式是将列值转换为固定长度的对象。标准方法是使用SUBSTRING函数。
BLOB或TEXT对象的最大大小由其类型确定,但在客户端和服务器之间实际可以传递的最大值由可用内存数量和通信缓存区大小确定。你可以通过更改max_allowed_packet变量的值更改消息缓存区的大小,但必须同时修改服务器和客户端程序。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

Created by Ripple, Ripple is used for cross-border payments, which are fast and low-cost and suitable for small transaction payments. After registering a wallet and exchange, purchase and storage can be made.

The difference between decentralized exchanges and hybrid exchanges is mainly reflected in: 1. Trading mechanism: Decentralized exchanges use smart contracts to match transactions, while hybrid exchanges combine centralized and decentralized mechanisms. 2. Asset control: Decentralized exchange users control assets, and mixed exchange ownership centralization and decentralization. 3. Privacy protection: Decentralized exchanges provide high anonymity, and hybrid exchanges require KYC in centralized mode. 4. Trading speed and liquidity: Decentralized exchanges are slower, liquidity depends on user pool, and hybrid exchanges are more fast and liquid in centralized mode. 5. Platform governance: Decentralized exchanges are governed by community governance, and hybrid exchanges are jointly governed by communities and centralized teams.

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.
