How to save base64 to blob of MySQL?

When saving text in a website, is it better to save it in a .txt file or in a MySQL database?

  • Also, what are the disadvantages of each, and which data type (VARCHAR, TEXT...) should I use to save it in a MySQL database?

  • Answer:

    Better is a litte subjective here. It really depends on what you're wanting to do with the text after you've saved it. If you're going to want to index it, search it, and re-display it on the site then you should save it in the database. If you want to download it to your computer, or make it shareable at a filesystem level then making text files would be better. As to the data type, varchar is generally faster with less overhead (it's stored with the table, whereas text and blob are stored outside of the table), but you do have a tradeoff as more data is added to a varchar column it gets slower, and at that point text or blob would be faster.... The problem is which one is best is dependent on the hardware and the data you're storing.

Chris Pickett at Quora Visit the source

Was this solution helpful to you?

Other answers

If you need to sort, search or filter your data, you are certainly better off with storing your data in a database. Sorting, searching or filtering records is what databases are made for! I have seen some web site management systems or mail servers which store data as files not fields, they may be easy to move from btw servers or run free text search on, but that's among the few advantages. Nearly every data system is based on records, fields, keys and relations between keys, and that's actually what a database is.

Harald Groven

Chris Pickett's answer covers the most important point. I would mention specifically that if extensive text searching is involved, you may want to avoid naive options in MySQL and look into Sphinx, Lucene, etc, for fast, flexible and scalable searching.

Toby Thain

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.