Maximum length for MySQL TEXT field types
Posted February 4th, 2009 in MySql
MySQL supports 4 TEXT field types (TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT) and this post looks at the maximum length of each of these field types.
MyISAM tables in MySQL have a maximum size of a row of 65,535 bytes, so all the data in a row must fit within that limit. However, the TEXT types are stored outside the table itself and only contribute 1 to 4 bytes towards that limit. (For more information about this refer to the MySQL Manual - Data Storage Requirements chapter).
TEXT data types are also able to store much more data than VARCHAR and CHAR text types so TEXT types are what you need to use when storing web page or similar content in a database.
The maximum amount of data that can be stored in each data type is as follows:
| TINYTEXT | 256 bytes | |
| TEXT | 65,535 bytes | ~64kb |
| MEDIUMTEXT | 16,777,215 bytes | ~16MB |
| LONGTEXT | 4,294,967,295 bytes | ~4GB |
In most circumstances the TEXT type is probably sufficient, but if you are coding a content management system it's probably best to use the MEDIUMTEXT type for longer pages to ensure there are no issues with data size limits.
Related posts:
- String concatenation with MySQL - Part 1 (Wednesday, March 4th 2009)
- How to change the storage engine a MySQL table uses (Saturday, January 17th 2009)
- How to tell which storage engine a MySQL table uses (Tuesday, January 13th 2009)
- Upper case and lower case strings with MySQL (Tuesday, July 29th 2008)
- Renaming a table in MySQL (Wednesday, July 2nd 2008)
- Find the length of the longest string in MySQL (Friday, May 9th 2008)

Comments
blog comments powered by Disqus