2014-04-24 11:20
浏览 1.0k


When I first learnt about field types in MySQL I would define anything that was not a number as a VARCHAR and set the length to anything. 500 2000, but am I right in saying the maximum is actually 255?

If this is the case, why does MySQL let me define columns with much larger lengths and what is it actually doing? Will it allow larger lengths? Does it define the column / field as something else?

Any advice welcomed.

图片转代码服务由CSDN问答提供 功能建议

当我第一次了解MySQL中的字段类型时,我会将任何不是数字的东西定义为VARCHAR并设置 任何事情的长度。 500 2000,但我是否正确地说最大值实际上是255?

如果是这种情况,为什么MySQL允许我定义具有更大长度的列以及它实际上在做什么? 它会允许更大的长度吗? 它是否将列/字段定义为其他内容?


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

5条回答 默认 最新

  • doushui5587 2014-04-24 11:24

    This behavior was changed after 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.

    From The CHAR and VARCHAR Types documentation reference.

    解决 无用
    打赏 举报

相关推荐 更多相似问题