What is the maximum varchar length in MySQL? This is not a fixed number.
1. Restrictions
Field restrictions include the following rules when a field is defined:
A) Storage restrictions
The varchar field stores the actual content separately in the clustered index. The content starts with 1 to 2 bytes to indicate the actual length (2 bytes if the length exceeds 255 ), therefore, the maximum length cannot exceed 65535.
B) encoding length limit
If the character type is GBK, each character occupies a maximum of 2 bytes, and the maximum length cannot exceed 32766;
If the character type is utf8, each character occupies up to 3 bytes, and the maximum length cannot exceed 21845.
If the preceding limits are exceeded during definition, the varchar field is forcibly converted to the text type and generates a warning.
C) row length limit
In practice, the length of a varchar is limited by the length defined by a row. MySQL requires that the definition length of a row cannot exceed 65535. If the defined table length exceeds this value, a prompt is displayed.
Error 1118 (42000): Row size too large. The maximum row size for the used table type, not counting blobs, is 65535. You have to change some columns to text or blobs.