What is the MySQL VARCHAR max size?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
MySQL's VARCHAR type is a versatile string data type that holds data of varying length. Understanding its maximum size involves both SQL syntax and some knowledge of underlying storage. This article provides a detailed insight into the maximum size of the VARCHAR type in MySQL, including its variations under different versions and its impact on storage and performance.
What is VARCHAR?
VARCHAR(n) is a variable-length string data type in MySQL where n represents the maximum number of characters that the column can store. Unlike fixed-length types such as CHAR, VARCHAR allows you to store data of varying length, potentially reducing wasted storage space.
Maximum Size of VARCHAR
Character Count
The formal specification of VARCHAR in SQL:2003 states that the maximum length can be up to 65,535 bytes. However, this limit is not just about the characters; it includes additional overhead stored by MySQL to manage the VARCHAR column.
- Overhead:
VARCHARcolumns include 1 or 2 additional bytes to store the length of the data. If the length of the stored string is less or equal to 255 bytes, 1 byte is used for length. If it's more, 2 bytes are needed. - Character Encoding: The actual maximum number of characters that can be stored can vary based on character set. For instance,
utf8mb4, a common charset that supports full Unicode, can require up to 4 bytes per character. Thus, the formula to calculate the maximum number of characters is as follows:#### Practical Example
Consider a scenario where you're using the utf8mb4 charset:
- Each character may require up to 4 bytes.In this case, the maximum number of characters you can store in a
VARCHARusingutf8mb4is 16,383.
Influential Factors on VARCHAR Size
- Row Size Constraints:
- A row in InnoDB may not extend a total of 65,535 bytes across all columns.
- Having multiple
VARCHARor other large columns can limit the potential size of a singleVARCHARcolumn.
- Other Column Types:
- MySQL provides
TEXT,MEDIUMTEXT,LONGTEXTfor larger text requirements that surpassVARCHARlimits, albeit with different storage and indexing properties.
- Table Definition Limits:
- The InnoDB table has its own storage constraints that can affect the effective use of
VARCHAR.
Considerations for Usage
- Performance: Using the largest possible
VARCHARsize may cause performance degradation due to increased I/O if not required by the application's logic. - Indexes: MySQL limits the size of index keys; this affects the indexing of large
VARCHARcolumns.
Summarizing the Key Constraints
| Constraint | Impact on VARCHAR |
| Maximum Storage | 65,535 bytes per row, including length overhead. |
| Length Bytes | Adds 1-2 bytes overhead per VARCHAR column. |
| Character Encoding | Affects how many characters fit based on bytes/char. |
Max Length (utf8mb4) | 16,383 characters with 4-byte max char encoding. |
| Row Constraints | Combined row size across all columns is limited. |
In conclusion, while VARCHAR is a highly flexible data type suitable for many use cases, it comes with considerations that must be addressed in terms of storage capacity, performance characteristics, and character set constraints. When designing a database schema, it's crucial to understand these parameters to ensure efficient and effective database utilization.

