LONGTEXT is the largest of MySQL’s four text column types (TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT). It holds any character data such as large documents, HTML, JSON, or logs that exceed MEDIUMTEXT’s 16 MB cap, topping out at roughly 4 GB. LONGTEXT columns use 4 bytes for length metadata plus the stored characters, so total space equals data size + 4 bytes. They respect the table’s CHARACTER SET and COLLATION; UTF-8 may reduce maximum character count because each character can occupy up to 4 bytes. LONGTEXT cannot be indexed in full, but you can prefix-index the first N bytes or use FULLTEXT indexes (InnoDB 5.6+). LONGTEXT behaves like other BLOB/TEXT types: it ignores default values in most MySQL versions prior to 8.0.13, cannot be part of a primary key, and requires the value to be supplied on INSERT unless the column is NULLable. Be mindful of memory and network overhead when selecting LONGTEXT, and use streaming functions when handling very large rows.
TINYTEXT, TEXT, MEDIUMTEXT, VARCHAR, BLOB, CLOB, FULLTEXT index, CHARACTER SET, COLLATION
MySQL 3.23
LONGTEXT can store up to 4,294,967,295 bytes, or roughly 4 GB, of character data.
You cannot create a full B-tree index on LONGTEXT. Use prefix indexes (e.g., column_name(255)) or FULLTEXT indexes on InnoDB 5.6+.
Before MySQL 8.0.13, TEXT and BLOB types could not have defaults. Starting in 8.0.13, LONGTEXT columns can specify a default string.
Pick LONGTEXT when you need to hold text larger than 16 MB (MEDIUMTEXT’s limit) such as large HTML pages, logs, or big JSON blobs.