VARCHAR(20000)在MySQL中有效吗? [英] Is a VARCHAR(20000) valid in MySQL?

查看:173
本文介绍了VARCHAR(20000)在MySQL中有效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要澄清MySQL中varchar字段的最大长度.

I’m in need of some clarification of the maximum length of a varchar field in MySQL.

我一直以为最大长度为255(255是什么?我假设的字符,但这可能会使我感到困惑).看一下我们正在与之合作的外部公司建立的数据库表,我看到一个字段设置为varchar(20000),其中保存的XML块长度超过255个字符.为什么这样做? 20000是有效值吗?

I’ve always thought the max length was 255 (255 what? Characters I’ve assumed, but this might be a source of my confusion). Taking a look at the tables of a database set up by an external company we’re working with, I see a field set-up as varchar(20000), holding chunks of xml longer than 255 characters. Why does this work? Is 20000 a valid value?

一些谷歌搜索发现,在mysql中varchar的限制为65,535个字节,我看到varchar(65535)

A bit of googling has revealed that in mysql varchar has a limit of 65,535 bytes, and I see varchar(65535) in use, so how does the 255 limit relate to this?

推荐答案

注意MySQL版本.

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.

我拥有哪个版本的MySQL?

运行以下查询...

What version of MySQL do I have?

Run the following query...

select version() as myVersion

这篇关于VARCHAR(20000)在MySQL中有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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