(Transfer) Difference between blob and text

(mysql has no clob)

 ( In most respects, BLOB columns can be thought of as VARBINARY columns that can be large enough. Likewise, TEXT columns can be thought of as VARCHAR columns. )

 

There are four types of text: TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT, which correspond to different lengths. text is a non-binary string, and needs to specify a character set, and checksum sorting according to that character set. Only plain text can be stored, which can be seen as an extension of VARCHAR when the length is insufficient.

 

Blobs are also divided into 4 types: TINYBLOB, BLOB, mediumblob and LongBlob, which correspond to different lengths. Blobs store binary data, so no character set verification is required. In addition to storing text information, blobs are also stored in binary format. Information such as pictures can be saved, and blob can be regarded as an extension of VARBINARY when the length is insufficient.

 

--------------------------------------

 

 

MySQL exists text and blob:

(1) same

  • During the storage or retrieval of TEXT or BLOB columns, there is no case conversion. When not running in strict mode, if you assign a value to a BLOB or TEXT column that exceeds the maximum length of the column type, the value is truncated to Guaranteed to fit. A warning will be generated if the truncated character is not a space. With strict SQL mode, an error is generated and the value is rejected rather than truncated with a warning.
  • BLOB and TEXT columns cannot have default values.
  • Trailing spaces are not removed when saving or retrieving values ​​for BLOB and TEXT columns. (This is the same for VARBINARY and VARCHAR columns).
  • For indexes on BLOB and TEXT columns, the length of the index prefix must be specified. For CHAR and VARCHAR, the prefix length is optional.

(2) different 

 text :

  • TEXT values ​​are case insensitive
  • Text is treated as a non-binary string
  • TEXT columns have a character set and values ​​are sorted and compared according to the collation rules of the character set
  • TEXT columns can be treated as VARCHAR columns
  • MySQL Connector/ODBC defines TEXT value as LONGVARCHAR
  • BLOB can store pictures, but TEXT cannot. TEXT can only store plain text files. The four TEXT types TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT correspond to the four BLOB types and have the same maximum length and storage requirements.

blob:  

  • Sorting and comparison of BLOB values ​​is performed in a case-sensitive manner;
  • BLOBs are treated as binary strings;
  • BLOB columns have no character set, and sorting and comparison are based on the numeric value of the column value bytes.

  • In most respects, a BLOB column can be thought of as a VARBINARY column that can be large enough

  • MySQL Connector/ODBC defines BLOB value as LONGVARBINARY
  • A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types TINYBLOB, BLOB, MEDIUMBLOB and LONGBLOB differ only in the maximum length of the value they can hold.

(3) Other:

The VARCHAR, BLOB and TEXT types are variable-length types, for which storage requirements depend on the actual length of the column value (denoted by L in the preceding table), not on the maximum possible size of the type. For example, a VARCHAR(10) column can store a string with a maximum length of 10 characters. The actual storage needs to be the length of the string, plus 1 byte to record the length of the string. For the string 'abcd', L is 4 and the storage requirement is 5 bytes.
    BLOB and TEXT types require 1, 2, 3 or 4 bytes to record the length of the column value, depending on the maximum possible length of the type. VARCHAR needs to have a defined size, with a maximum limit of 255; TEXT does not. If you assign a value that exceeds the maximum length of the column type to a BLOB or TEXT column, the value is truncated to fit it.

CHAR(n) fixed length, up to 255 characters 
VARCHAR(n) variable length, MySQL  4.1 and earlier up to 255 characters, MySQL 5 and later up to 65535 bytes 
TINYTEXT variable length, up to 255 characters 
TEXT variable length, up to 65535 characters 
MEDIUMTEXT variable length, up to 16777215 (2^24 - 1) characters 
LONGTEXT variable length, up to 4294967295 (2^32 - 1) (4G) characters

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326469094&siteId=291194637