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

查看:1213
本文介绍了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个字节,因为它们的内容与行的其余部分分开存储.阅读有关表列数和行大小的限制的更多信息.

单列可容纳的最大大小,在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.

四种TEXT类型是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类型的详细信息

  • Ref for MySQLv8.0 https://dev.mysql.com/doc/refman/8.0/en/blob.html
  • Ref for MySQLv5.7 http://dev.mysql.com/doc/refman/5.7/en/blob.html
  • Ref for MySQLv5.6 http://dev.mysql.com/doc/refman/5.6/en/blob.html
  • Ref for MySQLv5.5 http://dev.mysql.com/doc/refman/5.5/en/blob.html
  • Ref for MySQLv5.1 http://dev.mysql.com/doc/refman/5.1/en/blob.html
  • Ref for MySQLv5.0 http://dev.mysql.com/doc/refman/5.0/en/blob.html

更多

数据类型存储要求上查看更多详细信息满足所有数据类型的存储要求.

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

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

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