简体   繁体   English

如何在不知道最大数据大小的情况下存储和索引非常大的文本项

[英]How can I store and index very large text items without knowing the max data size

I am new to MySQL and recently I am working on a Blogging website, but the serious problem which I am facing is how can I store large block of Text data in MySQL. 我是MySQL的新手,最近我在Blogging网站上工作,但是我面临的严重问题是如何在MySQL中存储大量文本数据。 I was thinking of using the type as Text but I think that MySQL doesn't support FULLTEXT search for this type, as a result searching through this might take tremendous amount of time and resource. 我曾考虑将类型用作Text,但是我认为MySQL不支持FULLTEXT搜索该类型,因此搜索此类型可能会花费大量时间和资源。

Is there an alternative way to store large text in MySQL which can be search very quickly? 是否有其他方法可以在MySQL中存储大文本,并且可以快速搜索呢?

As of version 5.6 MySQL does indeed support FULLTEXT indexing for the TEXT datatype, in InnoDB and MyISAM access-method tables. 从5.6版开始,MySQL确实支持InnoDB和MyISAM访问方法表中的TEXT数据类型的FULLTEXT索引。 Check your MySQL server version if you can't get it to work. 如果无法正常使用,请检查您的MySQL服务器版本。

You could use VARCHAR(64000) or some such data type to store your text. 您可以使用VARCHAR(64000)或某些此类数据类型来存储文本。 That will work for almost every blogging application: 64K of the sort of text you can subject to a FULLTEXT search is a lot of text. 这几乎适用于所有博客应用程序:可以接受FULLTEXT搜索的64K文本中有很多文本。 To compare, the entire text of Shakespeare's HAMLET takes 188K , and so would fit in three of these rows. 相比之下, 莎士比亚《哈姆雷特》的整个文本需要188K ,因此可以容纳其中的三行。 Therefore, you could adhere to the YAGNI principle and complete your project. 因此,您可以遵循YAGNI原则并完成您的项目。

You could easily rig up your table structure to allow continuation rows in the table containing your full text. 您可以轻松地建立表格结构,以允许表格中包含全文的连续行。 An extra column that, if not NULL, means "this column continues the text in the row with a certain ID" would work well. 一个额外的列(如果不为NULL,则表示“此列以特定ID继续行中的文本”)会很好地工作。

But your best bet is still to get the FULLTEXT index to work on the data type you want. 但是最好的选择还是让FULLTEXT索引在所需的数据类型上运行。

Edit If you cannot upgrade your old version of the MySQL server at this time, use VARCHAR(64000). 编辑如果此时不能升级旧版本的MySQL服务器,请使用VARCHAR(64000)。 Later, when you can upgrade, you can alter the columns to change over to TEXT. 以后,当您可以升级时,可以更改列以切换为TEXT。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM