08/01: MySQL > String Data Types
Category: Study
Posted by: hajime osako
CHAR Fixed length up to 255 characters VARCHAR Variable length up to approx. 65,535 characters (+ 1 byte for a less than 256, 2 bytes otherwise*) TINYTEXT Variable length up to 255 characters (+ 1 byte*) TEXT Variable length up to 65,535 characters (+ 2 bytes*) MEDIUMTEXT Variable length up to 16,777,215 chars (+ 3 bytes*) LONGTEXT Variable length up to 4,294,967,295 chars (+ 4 bytes*)* extra storage space for character length
For variable-length (VARCHAR, TEXT) columns, MySQL allocates only the required amount of space. That means if the character is triple-byte, one character use 3 bytes plus a length byte.
Non-binary strings have a character set and a character set might have many collations (string order).
The collation decides if uppercase and lowercase versions and/or accent marks of a given character are equivalent.
A collation can be a binary collation. One effect of this is that for character sets with uppercase and lowercase characters or accented characters, the collation is case sensitive and accent sensitive.
mysql# SHOW COLLATION LIKE 'latin1%';
Each collation name ends with _ci, _cs or _bin, signifying that the collation is Case Insensitive, Case Sensitive or BINary. The binary columns are suitable for raw data such as images or compressed data.
BINARY Fixed length, binary string VARBINARY Variable length, binary string BLOB variable length, binary string (TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB)
ENUM A fixed set of legal values up to 65,535 SET A fixed set of legal values up to 64MySQL represents ENUMerations as integers internally.
Illigal value is stored as 0 and display as the empty string. (in strict SQL mode, an error occurs when you try to store an invalid value.)
MySQL represents SET as a bitmap using one bit per member.
It's ignored if you try to store an invalid value into a SET column (only valid values are stored)
When you do SELECT, INSERT or UPDATE, you can use either string or internal integer value (it could be confusing though.)