我需要澄清一下 MySQL 中 varchar 字段的最大长度。
我一直认为最大长度是 255(255 什么?我假设的字符,但这可能是我困惑的根源)。查看我们正在合作的外部公司设置的数据库表,我看到一个字段设置为 varchar(20000),包含超过 255 个字符的 xml block 。为什么这行得通? 20000 是有效值吗?
谷歌搜索显示,在 mysql 中,varchar 的限制为 65,535 个字节,我看到 varchar(65535) in use ,那么 255 限制与此有何关系?
最佳答案
注意 MySQL 版本。
http://dev.mysql.com/doc/refman/5.0/en/char.html
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?
运行以下查询...
select version() as myVersion
关于mysql - VARCHAR(20000) 在 MySQL 中有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1303476/