Home  >  Article  >  Database  >  What is the maximum length of varchar in mysql?

What is the maximum length of varchar in mysql?

hzc
hzcOriginal
2020-06-18 14:44:5917024browse

What is the maximum length of varchar in mysql?

What is the maximum length of varchar in mysql?

varchar in mysql can store up to 65535 bytes of data.

The maximum length of varchar is limited by the maximum row length (max row size, 65535bytes). 65535 is not a very precise upper limit, and you can continue to reduce this upper limit. 65535 bytes include the length of all fields, the length identifier of the variable-length field (each variable-length field uses an additional 1 or 2 bytes to record the actual data length), and the accumulation of NULL flag bits.

What is the maximum length of varchar in mysql?

Extended information

1. Varchar storage rules: below mysql4.0 version, varchar(20) refers to 20 Bytes, if UTF8 Chinese characters are stored, only 6 can be stored (each Chinese character is 3 bytes). MySQL version 5.0 or above, varchar(20) refers to 20 characters, regardless of whether numbers, letters or UTF8 Chinese characters are stored ( Each Chinese character is 3 bytes) and can store 20 characters. The maximum size is 65532 bytes.

2. Varchar is subject to encoding length restrictions: if the character type is gbk, each character can occupy up to 2 bytes, and the maximum length cannot exceed 32766;

If the character type is utf8, each character Each character can occupy up to 3 bytes, and the maximum length cannot exceed 21845.

Recommended tutorial: "mysql tutorial"

The above is the detailed content of What is the maximum length of varchar in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn