Character data can also be stored in one of the set of TEXT fields. The differences between these fields and VARCHAR fields are small:
- Prior to version 5.0.3, MySQL would remove leading and trailing spaces from VARCHAR fields.
- TEXT fields cannot have default values.
- MySQL indexes only the first n characters of a TEXT column (you specify n when you create the index).
What this means is that VARCHAR is the better and faster data type to use if you need to search the entire contents of a field. If you will never search more than a certain number of leading characters in a field, you should probably use a TEXT data type.
- TINYTEXT(n) Up to n (<= 255) Treated as a string with a character set
- TEXT(n) Up to n (<= 65535) Treated as a string with a character set
- MEDIUMTEXT(n) Up to n (<= 1.67e+7) Treated as a string with a character set
- LONGTEXT(n) Up to n (<= 4.29e+9) Treated as a string with a character set
The data types that have smaller maximums are also more efficient; therefore, you should use the one with the smallest maximum that you know is enough for any string you will be storing in the field.