[英]What datatype should i choose for mysql db to store a paragraph text which includes special characters as well?
In my MySql DB I want to store some text which will be a mimimun of 1000 words, it will contain some special characters like "",'()<>-.;;
在我的 MySql 数据库中,我想存储一些最少 1000 个单词的文本,其中将包含一些特殊字符,如
"",'()<>-.;;
data will be passed using php.数据将使用 php 传递。
VARCHAR columns are variable-length strings. VARCHAR 列是可变长度的字符串。 The length can be specified as a value from 0 to 65,535.
长度可以指定为 0 到 65,535 之间的值。 The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns in a tabel) and the character set used.
VARCHAR 的有效最大长度取决于最大行大小(65,535 字节,在表中的所有列之间共享)和使用的字符集。 VARCHAR is easier to use.
VARCHAR 更容易使用。
TEXT data type can hold up to 64KB. TEXT 数据类型最多可容纳 64KB。 Don't forget to escape the ' character (as in \') in TEXT field data.
不要忘记在 TEXT 字段数据中转义 ' 字符(如 \')。
you can use BLOB datatype to store your text.您可以使用BLOB数据类型来存储您的文本。 it can handle up to 64KB of data which is around 64000 characters.
它可以处理多达 64KB 的数据,大约 64000 个字符。
There are several datatypes that hold text.有几种保存文本的数据类型。 When you declare any of them you can also specify their collation and character set.
当您声明它们中的任何一个时,您还可以指定它们的排序规则和字符集。 For example:
例如:
CREATE OR REPLACE TABLE mytable {
mytext VARCHAR(2000) COLLATE utf8mb4_general_ci
)
This gives you a place to store up to 2000 characters of Unicode text.这使您可以存储多达 2000 个字符的 Unicode 文本。 Each Unicode character can take from 1 to 4 bytes of storage.
每个 Unicode 字符可以占用 1 到 4 个字节的存储空间。 Unicode, as you know, handles many different human scripts, not to mention emojis and math symbols.
如您所知,Unicode 可以处理许多不同的人类文字,更不用说表情符号和数学符号了。
To store text you have要存储您拥有的文本
CHAR()
data type if you know upfront exactly how many characters you must store. CHAR()
数据类型,如果您预先知道必须存储多少个字符。VARCHAR()
data type. VARCHAR()
数据类型。 It has best performance especially if you want to filter on it.LONGTEXT
... up to 4GiB in your text. LONGTEXT
...文本中最多 4GiB。 This is what WordPress uses for content, for what it's worth.MEDIUMTEXT
... up to 16MiBMEDIUMTEXT
TEXT
... up to 64KiB TEXT
... 高达 64KiBTINYTEXT
... up to 255 bytes (useless, use VARCHAR(255)
instead) TINYTEXT
... 最多 255 个字节(没用,改用VARCHAR(255)
) These all have reasonable overhead in terms of disk space used.这些都在使用的磁盘空间方面具有合理的开销。
If you want to put indexes on VARCHAR()
columns limit their size to VARCHAR(768)
.如果要在
VARCHAR()
列上放置索引,请将它们的大小限制为VARCHAR(768)
。
Pro tip : Avoid the LOB data types unless you absolutely need them.专业提示:避免使用 LOB 数据类型,除非您绝对需要它们。 They make the server do extra work when you use them in SELECT or WHERE clauses.
当您在 SELECT 或 WHERE 子句中使用它们时,它们会使服务器做额外的工作。 Use
VARCHAR()
instead.请改用
VARCHAR()
。
Mediumtext has known bugs associated with inserting into a mediumtext field, so I would recommend staying away from that, as a paragraph is not enough to warrant it. Mediumtext 已知存在与插入 mediumtext 字段相关的错误,因此我建议远离它,因为段落不足以保证它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.