mysql - MySQL VARCHAR 的最大大小是多少?

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

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

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

最佳答案

请记住,MySQL 有最大行大小限制

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 前后不同

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 等多字节字符集,则限制会更低。

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

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

更多

在 Data Type Storage Requirements 上查看更多详细信息它处理所有数据类型的存储要求。

https://stackoverflow.com/questions/13506832/

相关文章:

mysql - 错误 1396 (HY000) : Operation CREATE USER fa

mysql - MySQL 中的 utf8mb4 和 utf8 字符集有什么区别?

sql - 如何通过一个 SQL 查询获得多个计数?

mysql - 将 MySQL 与 Entity Framework 一起使用

mysql - 如何检查mysql数据库是否存在

mysql - 如何将 CSV 文件导入 MySQL 表?

mysql - UTF-8:一般?垃圾桶?统一码?

mysql - 如何在 MySQL 中获取两个值的最大值?

mysql - 只用 mysqldump 转储数据而没有任何表信息?

sql - 从一个表中查找另一个表中不存在的记录