MySQL 数据库中存储文章的字段/数据类型
我不禁相信这个话题已经被写了一遍又一遍,但我很难找到任何好的、可靠的信息。
我应该使用什么数据类型来存储 200 到 400 个字的文本?篇幅较长、接近两三千字的文章又如何呢?
哪些选项会影响我的决定?我不打算搜索这些数据,但我不能完全排除我稍后可能想要搜索的可能性。
不幸的是,我的背景是 MS Access,唯一的选择是备注字段。对于 MySQL 来说,事情似乎并不那么简单。
I can't help but believe this topic has been written about over and over again but I'm having trouble finding any good, solid information.
What data type should I use to store 200 to 400 words of text? What about longer articles that could approach two or three thousand words?
What options should affect my decision? I don't plan to search this data but I can't completely rule out the possibility that I may want to do that later.
Unfortunately my background is MS Access where the only option for this was a memo field. It doesn't appear to be quite so simple with MySQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是 MySQL 5.0.3 或更高版本,请转至 VARCHAR。它可以容纳 65k 字节。只要每行只有 1 个 long VARCHAR,就应该没问题。
否则就用文字。
来自mysql手册:
也很高兴知道(来自手册):
在制定使用 TEXT 的查询时确实应该考虑
If you're using MySQL 5.0.3 or later, go VARCHAR. It can hold 65k bytes. As long as you have only 1 long VARCHAR per row, you should be fine.
Otherwise go with text.
From the mysql manual:
Also nice to know (from the manual):
which you really should take into account when formulating queries which use TEXT.
TEXT
字段应该足够大以存储大多数文章。似乎与Access的Memo类型差不多。它最多可以容纳 65535 个字符,这大约是...我不知道...平均 10-12,000 个单词?A
TEXT
field should be big enough to store most articles. Seems to be about equivalent to Access's Memo type. It can hold up to 65535 chars, which would be somewhere around...i dunno...10-12,000 words, on average?TEXT
数据类型对于您的情况来说是一个安全的选择,VARCHAR
通常在需要索引或需要存储明确定义的值(IP地址、邮政编码等)。The
TEXT
data type is a safe bet for your situation,VARCHAR
s are usually used when they need to be indexed or there is a well-defined value to be stored (IP address, zip code, etc).