MySQL 数据类型和类型是什么?属性应该用来存储大量的html格式数据吗?
我正在使用 PHPMyAdmin 设置数据库,许多字段将是大块 HTML。
MySQL 数据类型和类型是什么?属性应该用于存储大量 HTML 数据的字段吗?
I'm setting up a database using PHPMyAdmin and many fields will be large chunks of HTML.
What MySQL datatype & attributes should be used for fields that store large amounts of HTML data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
文本、中文本或长文本
TEXT, MEDIUMTEXT, or LONGTEXT
我建议不要在数据库中存储大块 HTML(或其他文本数据)。我发现将文件存储为文件并将文件名放入数据库通常更有用。
另一方面,如果您通过 phpMyAdmin 执行所有操作,则可能无法使用该选项。
I would recommend against storing large chunks of HTML (or other text data) in a database. I find that it's often far more useful to store files as files, and put a filename in the database instead.
On the other hand, if you're doing everything through phpMyAdmin, you may not have that option available to you.
您确实应该从文档开始,然后如果您对在那里找到的数据类型有疑问,请尝试要求一些说明。但在提出问题之前了解数据类型确实很有帮助:此处的文档:
http://dev.mysql.com/doc/refman/5.4/en/data-types.html
也就是说,仔细看看文本和 blob。文本将存储大量文本信息(可能是一个不错的选择),其中 blob 是为二进制数据设计的。根据查询函数及其操作的数据类型,这确实会有所不同。
You really really should start with the documentation, then if you have questions based on the data types you find there, try to ask for some clarification. But it really helps to understand what the datatypes are before asking the question: Documentation here:
http://dev.mysql.com/doc/refman/5.4/en/data-types.html
That said, take a closer look at text and blob. Text will store a large body of textual information (probably a good choice) where blob is designed for binary data. This does make a difference based on the query functions and what data types they operate on.
我认为你可以用简单的
TEXT
存储 HTML 字段。如果您的 html 超过 64KB,那么您可以使用MEDIUMTEXT
代替。另请参阅字符串类型的存储要求了解更多详细信息关于存储值的最大长度。
另请记住 Unicode 中的字符可能需要更多1 个字节来存储。
I think you can store HTML in simple
TEXT
field. If your html is more then 64KB then you can useMEDIUMTEXT
instead.See also Storage Requirements for String Types for more details about maximum length of stored value.
Also remember than characters in Unicode can require more then 1 byte to store.