String data type

The string data type is the most commonly used data type. Thanks to this, both text and various binary data (for example, pictures) are stored in the database.

In MySQL, it is represented by the following types:

CHAR and VARCHAR

TypeDescriptionRange of characters
CHAR(X)Contains non-binary strings. The length is fixed, you specify it when declaring. If the length of the string is less than the specified one, it is padded with right spaces to the specified length.The length can be any in the range from 0 to 255
VARCHAR(X)Contains non-binary strings. The length of the lines is dynamic.The length can be any in the range from 0 to 65.535

BINARY and VARBINARY

The BINARY and VARBINARY data types are similar to VARCHAR and CHAR except that they store binary strings.

TypeDescriptionRange of characters
BINARY(X)Contains binary strings. The length is fixed, you specify it when declaring.The length can be any in the range from 0 to 255
VARBINARY(X)Contains binary strings. The length of the lines is dynamic.The length can be any in the range from 0 to 65,535

BLOB and TEXT

BLOB is used to store large binary data such as pictures. TEXT is also for storing big data, but textual content.

The difference between them is that the sorts and comparisons of stored data for BLOB are case sensitive and not case sensitive in TEXT fields.

TypeDescriptionRange of characters
BLOBContains binary strings.Maximum length 65.535
TEXTContains text lines.Maximum length 65.535

BLOB and TEXT have additional subtypes that differ in the maximum data size that can be stored in them.

TypeRange of characters
TINYBLOBMaximum length 255
MEDIUMBLOBMaximum length 16,777,215
LONGBLOBMaximum length 4,294,967,295
TINYTEXTMaximum length 255
MEDIUMTEXTMaximum length 16,777,215
LONGTEXTMaximum length 4,294,967,295