What is the MySQL VARCHAR max size?(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 类型的更多详细信息
- 参考 MySQLv8.0 https://dev.mysql.com/doc/refman/8.0/en/blob.html
- 参考 MySQLv5.7 https://dev.mysql.com/doc/refman/5.7/en/blob.html
- 参考 MySQLv5.6 https://dev.mysql.com/doc/refman/5.6/en/blob.html
更多
查看有关数据类型存储要求 处理所有数据类型的存储要求.
Checkout more details on Data Type Storage Requirements which deals with storage requirements for all data types.
这篇关于MySQL VARCHAR 的最大大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL VARCHAR 的最大大小是多少?


- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01