I'm looking at storing multiple lines of data in MySQL (or your choice), an example would be a poem. I wouldn't know how many lines it could be and I have to keep its structure intact so when I go display it to my end users on a site it is properly formatted.
我正在寻找在MySQL(或你的选择)中存储多行数据,一个例子就是一首诗。我不知道它可以有多少行,我必须保持其结构完好无损,所以当我将它显示给我在网站上的最终用户时,它的格式正确。
I could be storing anywhere between 100 characters to 100,000. I'd rather shy from using plain text unless someone can help me figure out an easier method.
我可以存储100个字符到100,000之间的任何地方。我宁愿害羞使用纯文本,除非有人可以帮我找出一个更简单的方法。
2 个解决方案
#1
1
If you store the text in a simple format like Markdown then you can render it as HTML using any number of libraries that convert.
如果您以Markdown这样的简单格式存储文本,那么您可以使用任意数量的转换库将其呈现为HTML。
There's nothing wrong with storing large amounts of text in MySQL. For data over 1KB you should be using TEXT
for up to 64KB or LONG TEXT
for much larger amounts.
在MySQL中存储大量文本没有任何问题。对于超过1KB的数据,您应该使用最多64KB的TEXT或更大的数量的长文本。
VARCHAR
can go to longer lengths under newer versions of MySQL but it's probably not what you intend here.
VARCHAR可以在较新版本的MySQL下使用更长的长度,但它可能不是你想要的。
#2
1
If you're really worried about the formatting. You could also use a content editor that creates html code like <br/>
and lists for formatting. Then post that into your sql as a text.
如果你真的担心格式化。您还可以使用内容编辑器创建html代码,例如
用于格式化的列表。然后将其作为文本发布到您的SQL中。
Again, I'm not sure exactly if your worried about inputting data into mysql, or worried about displaying it from mysql (Hence, the content editor idea).
再一次,我不确定你是否担心将数据输入mysql,或担心从mysql显示它(因此,内容编辑器的想法)。
#1
1
If you store the text in a simple format like Markdown then you can render it as HTML using any number of libraries that convert.
如果您以Markdown这样的简单格式存储文本,那么您可以使用任意数量的转换库将其呈现为HTML。
There's nothing wrong with storing large amounts of text in MySQL. For data over 1KB you should be using TEXT
for up to 64KB or LONG TEXT
for much larger amounts.
在MySQL中存储大量文本没有任何问题。对于超过1KB的数据,您应该使用最多64KB的TEXT或更大的数量的长文本。
VARCHAR
can go to longer lengths under newer versions of MySQL but it's probably not what you intend here.
VARCHAR可以在较新版本的MySQL下使用更长的长度,但它可能不是你想要的。
#2
1
If you're really worried about the formatting. You could also use a content editor that creates html code like <br/>
and lists for formatting. Then post that into your sql as a text.
如果你真的担心格式化。您还可以使用内容编辑器创建html代码,例如
用于格式化的列表。然后将其作为文本发布到您的SQL中。
Again, I'm not sure exactly if your worried about inputting data into mysql, or worried about displaying it from mysql (Hence, the content editor idea).
再一次,我不确定你是否担心将数据输入mysql,或担心从mysql显示它(因此,内容编辑器的想法)。