Best way to store multiple lines of data in MySQL?

6.7k views Asked by At

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.

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.

2

There are 2 answers

0
tadman On BEST ANSWER

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.

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.

VARCHAR can go to longer lengths under newer versions of MySQL but it's probably not what you intend here.

3
Jared Drake On

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.

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).