CyberJunkie CyberJunkie - 1 year ago 190
MySQL Question

Maximum length for MYSQL type text

I'm creating a form for sending private messages and want to set the

value of a textarea appropriate to the max length of a
field in my mysql database table. How many characters can a type text field store? If a lot, would I be able to specify length in the db text type field as I would with varchar?

fyr fyr
Answer Source

See for maximum numbers:

TINYBLOB, TINYTEXT       L + 1 bytes, where L < 2^8    (255 Bytes)
BLOB, TEXT               L + 2 bytes, where L < 2^16   (64 Kilobytes)
MEDIUMBLOB, MEDIUMTEXT   L + 3 bytes, where L < 2^24   (16 Megabytes)
LONGBLOB, LONGTEXT       L + 4 bytes, where L < 2^32   (4 Gigabytes)

L is the number of bytes in your text field. So the maxmimum number of chars for text is 2^16 (using single-byte characters). Means 65535 chars(using single-byte characters).

UTF-8/MultiByte encoding: using MultiByte encoding each character might consume more than 1 byte of space. For UTF-8 space consumption is between 1 to 4 bytes per char.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download