MySQL的VARCHAR最大值是多少?
阿神
阿神 2017-04-17 11:09:16
0
3
826

我看很多MySQL的表里varchar(256),好像就没见过再大的了
varchar的最大值是多少?大于多少就不适合了?要用text

阿神
阿神

闭关修行中......

reply all(3)
阿神

According to the official documentation, VARCHAR can be up to 65535 bytes (this also means that a record has only this field, because a MySQL row can only contain 65535 bytes).

However, it is not possible to index such a long VARCHAR. For MyISAM, the first 1000 bytes can be indexed, and for InnoDB, it is only 767 bytes. (source based on)

What we are talking about here is bytes, taking into account encoding factors (UTF-8 characters occupy 1-3 bytes, GBK characters occupy two bytes), and all VARCHAR information requires 1 more byte (i.e. empty string Also occupies 1 byte), it is easier to use VARCHAR(256).

迷茫

@xuecan’s answer is very detailed, so I will add a few more. What you see should mostly be varchar(255) instead of 256. The reason is that in mysql versions below 4.1, the maximum length of varchar is limited to 255, and its data range can be 0~255 or 1~255 (according to different versions of the database) Certainly).

刘奇

I heard that this problem is related to encoding~ Generally speaking, the number of bytes will not be too much. Considering the scalability of text length, text can be used for large texts.
http://my.oschina.net/zimingforever/b...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template