Tinytext vs Text vs Mediumtext vs Longtext in MySQL: Key Differences
TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT are text data types that differ mainly in maximum storage size: TINYTEXT stores up to 255 bytes, TEXT up to 65,535 bytes, MEDIUMTEXT up to 16,777,215 bytes, and LONGTEXT up to 4,294,967,295 bytes. Choose the type based on how much text you need to store, balancing space and performance.Quick Comparison
Here is a quick table comparing the main features of each MySQL text type.
| Type | Max Length (Bytes) | Storage Overhead (Bytes) | Use Case |
|---|---|---|---|
| TINYTEXT | 255 | 1 | Very small text, like short comments or tags |
| TEXT | 65,535 | 2 | Normal text, like descriptions or articles |
| MEDIUMTEXT | 16,777,215 | 3 | Large text, like long documents or logs |
| LONGTEXT | 4,294,967,295 | 4 | Very large text, like books or JSON data |
Key Differences
The main difference between TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT is their maximum storage capacity. TINYTEXT can hold up to 255 bytes, which is suitable for very short strings. TEXT expands this limit to 65,535 bytes, enough for most typical text fields.
MEDIUMTEXT and LONGTEXT are designed for much larger text data. MEDIUMTEXT can store up to about 16 million bytes, while LONGTEXT can hold up to 4 billion bytes, making it ideal for extremely large text like entire books or large JSON documents.
Each type also has a small storage overhead: TINYTEXT uses 1 byte to store length, TEXT uses 2 bytes, MEDIUMTEXT uses 3 bytes, and LONGTEXT uses 4 bytes. Choosing a larger type than needed can waste space and affect performance.
Code Comparison
Here is how you define a TINYTEXT column and insert a short string.
CREATE TABLE example_tinytext (
note TINYTEXT
);
INSERT INTO example_tinytext (note) VALUES ('Short note');
SELECT note FROM example_tinytext;Longtext Equivalent
Here is how you define a LONGTEXT column and insert a very long string.
CREATE TABLE example_longtext ( content LONGTEXT ); INSERT INTO example_longtext (content) VALUES (REPEAT('A', 1000)); SELECT LENGTH(content) AS length FROM example_longtext;
When to Use Which
Choose TINYTEXT when you only need to store very short strings like tags or short labels. Use TEXT for typical text fields such as comments or descriptions. Opt for MEDIUMTEXT if you expect large text like long articles or logs. Use LONGTEXT only when you need to store extremely large text data like entire books or large JSON documents, as it uses more storage and can impact performance.
Key Takeaways
TINYTEXT stores up to 255 bytes, TEXT up to 65,535 bytes, MEDIUMTEXT up to 16,777,215 bytes, and LONGTEXT up to 4,294,967,295 bytes.LONGTEXT for small text.TEXT for most common text needs; reserve MEDIUMTEXT and LONGTEXT for very large content.