0
0
MysqlComparisonBeginner · 3 min read

Tinytext vs Text vs Mediumtext vs Longtext in MySQL: Key Differences

In MySQL, 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.

TypeMax Length (Bytes)Storage Overhead (Bytes)Use Case
TINYTEXT2551Very small text, like short comments or tags
TEXT65,5352Normal text, like descriptions or articles
MEDIUMTEXT16,777,2153Large text, like long documents or logs
LONGTEXT4,294,967,2954Very 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.

mysql
CREATE TABLE example_tinytext (
  note TINYTEXT
);

INSERT INTO example_tinytext (note) VALUES ('Short note');

SELECT note FROM example_tinytext;
Output
note ------ Short note
↔️

Longtext Equivalent

Here is how you define a LONGTEXT column and insert a very long string.

mysql
CREATE TABLE example_longtext (
  content LONGTEXT
);

INSERT INTO example_longtext (content) VALUES (REPEAT('A', 1000));

SELECT LENGTH(content) AS length FROM example_longtext;
Output
length ------ 1000
🎯

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

Choose the smallest text type that fits your data to save space and improve performance.
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.
Storage overhead increases with larger text types, so avoid using LONGTEXT for small text.
Use TEXT for most common text needs; reserve MEDIUMTEXT and LONGTEXT for very large content.
Inserting and querying large text fields can affect performance, so pick the right type carefully.