MySQL VARCHAR 的最大大小是多少? [英] What is the MySQL VARCHAR max size?

查看:45
本文介绍了MySQL VARCHAR 的最大大小是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 MySQL VARCHAR 类型的最大大小是多少.

I would like to know what the max size is for a MySQL VARCHAR type.

我读到最大大小受行大小限制,行大小约为 65k.我尝试将该字段设置为 varchar(20000) 但它说这太大了.

I read that the max size is limited by the row size which is about 65k. I tried setting the field to varchar(20000) but it says that that's too large.

我可以将它设置为 varchar(10000).我可以将其设置为的确切最大值是多少?

I could set it to varchar(10000). What is the exact max I can set it to?

推荐答案

记住 MySQL 有最大行大小限制

MySQL 表的内部表示的最大行大小限制为 65,535 字节,不包括 BLOB 和 TEXT 类型.BLOB 和 TEXT 列仅对行大小限制贡献 9 到 12 个字节,因为它们的内容与行的其余部分分开存储.阅读有关 表列数和行大小限制的更多信息.

The internal representation of a MySQL table has a maximum row size limit of 65,535 bytes, not counting BLOB and TEXT types. BLOB and TEXT columns only contribute 9 to 12 bytes toward the row size limit because their contents are stored separately from the rest of the row. Read more about Limits on Table Column Count and Row Size.

单个列可占用的最大大小,MySQL 5.0.3前后不同

VARCHAR 列中的值是可变长度的字符串.在 MySQL 5.0.3 之前,长度可以指定为 0 到 255 之间的值,在 5.0.3 及更高版本中可以指定为 0 到 65,535.MySQL 5.0.3 及更高版本中 VARCHAR 的有效最大长度受最大行大小(65,535 字节,在所有列之间共享)和使用的字符集的约束.

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

但是,请注意,如果您使用 utf8 或 utf8mb4 等多字节字符集,则限制会更低.

However, note that the limit is lower if you use a multi-byte character set like utf8 or utf8mb4.

使用 TEXT 类型来克服行大小限制.

Use TEXT types inorder to overcome row size limit.

四种文本类型是 TINYTEXT、TEXT、MEDIUMTEXT 和 LONGTEXT.它们对应于四种 BLOB 类型,并且具有相同的最大长度和存储要求.

The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements.

有关 BLOB 和 TEXT 类型的更多详细信息

更多

查看有关数据类型存储要求 处理所有数据类型的存储要求.

Checkout more details on Data Type Storage Requirements which deals with storage requirements for all data types.

这篇关于MySQL VARCHAR 的最大大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆