How does MySQL store long characters-----MySQL text differs from the BLOB field type

Source: Internet
Author: User
Tags mysql text truncated

field type select text type or blog difference see:

The following article focuses on the differences between MySQL text and the Blob field type, as well as an introduction to the actual application of MySQL text and blob field types, if you are interested in the actual operation of MySQL text related to the Blob field type, You will be able to click on the following articles to watch.

1.

BLOBs are binary large objects that can hold variable amounts of data, where blobs are divided into 4 types: Tinyblob,blob,mediumblob and Longblob, the lengths they hold are different.

Text is also divided into four categories: Tinytext, Text, Mediumtext, and Longtext

2.

A blob is treated as a binary string, and text is treated as a non-binary string;

Blob columns do not have a character set, and sort and compare numeric values based on column-valued bytes.

The text column has a character set, and the values are sorted and compared according to the collation rules of the character set.

In the process of storing or retrieving MySQL text or blob columns, there is no case conversion, and if you do not run in strict mode, if you assign a BLOB or text column A value that exceeds the maximum length of the column type, the value is truncated to ensure that it is appropriate. If the truncated character is not a space, a warning will be generated.

Using strict SQL mode generates an error, and the value is rejected instead of intercepted and given a warning. In most respects, you can treat a BLOB column as a varbinary column that is large enough. Similarly, you can treat the text column as a varchar column.

3.

BLOBs and text differ from varbinary and varchar in the following ways.

Blob and text columns cannot have default values.

Trailing spaces are not deleted when you save or retrieve the values of the Blob and text columns. (This is the same as varbinary and varchar columns).

For the index of the Blob and text columns, you must specify the length of the index prefix. For char and varchar, the prefix length is optional.

Long and long varchar correspond to the Mediumtext data type. This is to ensure compatibility. If the text column type uses the binary attribute, the column is assigned a two-element collation of the column character set.

MySQL connector/ODBC defines the BLOB value as LongVarBinary and the MySQL text value as LongVarChar. Because the blob and text values can be very long, you may encounter some constraints when using them.

The maximum size of a blob or text 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 available memory and the size of the communication buffer. You can change the size of the message buffer by changing the value of the Max_allowed_packet variable, but you must modify both the server and the client program. For example, you can use MySQL and mysqldump to change the client's Max_allowed_packet value.




How does MySQL store long characters-----MySQL text differs from the BLOB field type

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.