HOWTO · MySQL
Difference Between VARCHAR and TEXT in MySQL
Compare MySQL VARCHAR and TEXT by expected values, declared length, storage considerations, and query needs, then choose a suitable column type.
On this page
Choose VARCHAR when a value has a useful declared maximum and is commonly used in ordinary column queries. Choose TEXT when the content is longer or its practical size is less predictable. The right choice depends on the data you expect, the limit your application should enforce, and how queries use the column; neither type is universally faster or better.
What VARCHAR and TEXT Store
In MySQL, both VARCHAR and TEXT store character data, but they express different schema expectations. VARCHAR(n) declares a length for the column, making it a natural fit for values with a known maximum, such as a display name or a short label. A TEXT column is intended for longer text, such as a user comment or an article body, when a short declared maximum would not describe the data well.
These type names do not determine your application’s validation policy. Decide which values are acceptable before insertion, and make the column choice reflect that policy. For example, a phone number may be short but should not automatically be stored as a number: if it is treated as text, a VARCHAR with a suitable application-defined limit can represent it.
Length Limits and Storage Costs
The number in VARCHAR(n) is a declared character limit, while a stored value can be shorter. The actual storage and permitted size depend on the schema and MySQL’s applicable limits; character set and row definitions also matter. Because these details vary with your MySQL version, character set, and table definition, consult the documentation for your deployment instead of relying on one universal byte-cost or maximum-size calculation.
Do not choose a type based only on a claim that one always uses less space. Consider expected value lengths, the declared limit, and the broader table design. TEXT provides a type for longer content, while VARCHAR communicates a bounded value directly in the schema.
Indexing and Query Considerations
Index needs should be part of the design. Consider which columns your application filters, sorts, or joins on, and confirm the appropriate index definition for the MySQL version and schema you deploy. TEXT is not categorically unindexable, but its indexing options and constraints can depend on those details. Avoid assuming that either type guarantees a particular query speed; measure representative queries in your own environment when performance matters.
Choose a Type for Your Data
Start with the value’s meaning and expected range. A bounded label, email address, or display name often fits VARCHAR when you can set a useful limit. Longer user comments or article content may fit TEXT. These are examples, not fixed rules: an application may have different limits or query patterns.
Then consider how the column is used. If it is commonly searched or sorted, include that access pattern in the schema and index review. If the value has a clear product limit, validate it in the application before insertion and reflect the limit in the column design. This makes the intended behavior explicit without relying on unspecified server handling of oversized input.
Example Schema and Length Handling
A small profile table might use VARCHAR for bounded fields and TEXT for an optional biography. The inline schema CREATE TABLE profile (display_name VARCHAR(80), phone VARCHAR(32), biography TEXT); illustrates those roles; choose limits that match your own requirements and verify indexing choices for your deployment.
For an application-managed field limit, validate the value before passing it to the database. This Python illustration returns whether each value meets a configured character-count policy; application code can use a False result to reject a value. The example itself only reports the results: it does not reject input, demonstrate MySQL insertion behavior, or replace server-side constraints. The first value has 12 characters and is within the limit of 80; the second has 81 and is over it.
Run this example:
values = ["Ada Lovelace", "x" * 81]
max_characters = 80
for value in values:
print(len(value) <= max_characters)
True
False