Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space occupied by TEXT type column in MySQL

Tags:

mysql

I am aware of the fact that TEXT in MySQL can have maxlength of 65535 characters.

Now I create a table having one of the columns as TEXT and don't specify a length. Due to which it will take maxlength as 65535 default.

However if one of my records has a value for the TEXT column with length only as 10 characters, will the space allocated for 65535 characters be still reserved or will MySQL just use up memory required for 10 characters only?

like image 510
Navin Nagpal Avatar asked May 30 '16 06:05

Navin Nagpal


1 Answers

For TEXT datatype it would be like the Actual length in bytes of string value + (2 Bytes)

The manual says:

Variable-length string types are stored using a length prefix plus data. The length prefix requires from one to four bytes depending on the data type, and the value of the prefix is L (the byte length of the string). For example, storage for a MEDIUMTEXT value requires L bytes to store the value plus three bytes to store the length of the value.

VARCHAR, VARBINARY, and the BLOB and TEXT types are variable-length types. For each, the storage requirements depend on these factors:

  • The actual length of the column value
  • The column's maximum possible length
  • The character set used for the column, because some character sets contain multibyte characters

enter image description here

like image 69
Rahul Tripathi Avatar answered Oct 19 '22 16:10

Rahul Tripathi