Menu

MySQL MEDIUMTEXT: 16 MB Text Capacity and Character Limits

Updated on

MySQL MEDIUMTEXT stores nonbinary text values up to 16,777,215 bytes. This is a byte limit, not a fixed number of characters: the number of characters that fit depends on the column character set. For example, a multibyte character set uses more than one byte for some characters. See MySQL’s BLOB and TEXT type reference and string type syntax.

Define a MEDIUMTEXT column

CREATE TABLE blog_posts (
    post_id INT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    content MEDIUMTEXT NOT NULL
);

INSERT INTO blog_posts (post_id, title, content)
VALUES (1, 'A short post', 'Text content stored in a MEDIUMTEXT column.');

MEDIUMTEXT uses the table’s character set and collation unless they are specified for the column. The M limit counts bytes after encoding. To inspect a stored value, compare CHAR_LENGTH(content) (characters) with LENGTH(content) (bytes).

Choose among VARCHAR and TEXT types

Use VARCHAR when its effective limit fits the data and you need a variable-length string in a regular row. MySQL limits a table row to 65,535 bytes across its columns, so the maximum VARCHAR character count depends on the character set and other row columns. TEXT holds up to 65,535 bytes; MEDIUMTEXT raises that to 16,777,215 bytes; LONGTEXT raises it further to 4,294,967,295 bytes. Choose the smallest type that can hold the valid data rather than defaulting to MEDIUMTEXT for every text column.

These are type limits. The largest value a client can transfer is also limited by available memory and communication buffers, including max_allowed_packet on both client and server. MySQL may truncate overlength TEXT input and warn when strict SQL mode is disabled; strict mode rejects nonspace truncation. See the BLOB and TEXT type rules and SQL mode documentation.

MEDIUMTEXT is a character string with a character set and collation. For binary bytes such as an image or compressed file, use the corresponding BLOB family instead.