为什么如果我创建一个 varchar(65535),我会得到一个mediumtext?
mediumtext 和 varchar(65535) 是同一件事吗? 我这里的意思是它们都是直接将数据存储在表中还是 mediatext 类型存储指针? 我问这个问题是因为如果我尝试创建 varchar(65535) 它会自动转换为mediumtext(如果长度实际上大于21811)。
我有另一个相关问题:
我在表中有一些字段,我希望能够存储大量字符(大约 10'000)。但实际上,它几乎总是存储不超过 10 个字符。
所以我的问题是,我是否需要使用 text 或 varchar(10000) 类型才能获得最佳性能?
我相信 varchar 类型更适合这种情况。
预先感谢您的回答。
编辑
我不明白的是为什么他们说从 mysql 5.0.3 开始,我们可以创建一个 varchar(65535) 但当我们尝试这样做时,它会将其转换为中型文本。对我来说,varchar 和 text(包括mediumtext)之间的区别在于它们的存储方式(是否使用指针)。 那么为什么他们说我们可以创建长度为 65535 的 varchar 如果我们不能呢?
Does a mediumtext and a varchar(65535) are the same thing ?
What I mean here is do they both store the data directly in the table or do the mediumtext type is storing a pointer ?
I'm asking this because if I try to create a varchar(65535) it is automatically transform into a mediumtext (if the length is bigger than 21811 actually).
I've got another related question which is:
I've got some fields in a table that I want to be able to store a lot of characters (around 10'000). But in reality, it will almost all the time store no more than 10 characters.
So my question is, do I need to use a text or a varchar(10000) type for best performance ?
I believe a varchar type is more appropriate for this case.
Thanks in advance for your answers.
Edit
The thing I don't understand is why they say that since mysql 5.0.3, we can create a varchar(65535) but when we try to do this, it convert it to a mediumtext. For me the difference between varchar and text (mediumtext include) is the way how they are store (using a pointer or not).
So why do they say that we can create varchar with a length of 65535 if we can't?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在回答我自己的问题:
那是因为我使用的是多字节字符。如果您使用 utf-8 排序规则,则将无法创建大约超过 21000 个字符的 varchar。但如果你使用ascii,你就会的。
I'm answering to my own question:
That's because I'm using a multi-byte character. If you use an utf-8 collation, you will not be able to create a varchar with about more than 21000 chars. But if you use ascii, you will.
根据 mysql.com,mediumtext 的长度是 L + 3 个字节。对我来说,这意味着如果你有一个空字段,它将是 3 个字节。如果您有一个空 varchar,则该字段的长度将为 1 个字节。
这里是明确提到
According to mysql.com the length of mediumtext is L + 3 bytes. To me this means that if you have an empty field it will be 3 bytes. If you have an empty varchar the length of this field will be 1 byte.
Here is clearly mentioned