1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2010
    Mumbai, India
    Rep Power

    MySQL vs. Text Files

    I've been wondering which is better for moderately small web-based projects: an SQL database or just a text file. It really isn't that hard to write a couple classes that edit and read files. Heck, they can be decrypted if the data is sensitive. There are several factors to consider, of course:

    1. Portability. I'd say that text files are far more portable as you can just copy+paste.
    2. Speed. Not sure about which can be loaded faster.
    3. Security. I guess you don't have to worry about database login information with text files and encryption can be applied to text files with sensitive data. However there are plenty of vulnerabilities I'm sure I'm not aware with with both.
    4. Ease. Databases would probably be easier, as you wouldn't have to worry about data formatting as much.

    What do y'all think? I've always wondering if databases are a bit over kill for small amounts of data being stored. I can imagine it being necessary for something big like a forum or CMS, though.
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Rep Power
    I would say there is at least 3 thing to consider:
    1. The amount of data
    2. How often the data is (re)written
    3. (concurrent) number of users accessing the data

    A forum or CMS have a lot of data read or writen by a (possible) large number of users; this makes database a good option because it has already been optimized for data "manipulation" (search/read/write).

    Regarding the portability, there are options like MS Access of SQLite.
  4. #3
  5. Business Analyst
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2004
    The 'Ville
    Rep Power
    Firebird DB also has a version that requires no installation, just a few files placed in your application directory. Only good for one connection, but it's very lightweight and if you do choose to install the server (which would work for multiple connections) it requires almost zero change to the application.

    If you do text files I would consider using XML rather than CSV's, particularly if there are relationships in the data (like foreign keys in a database).
    Discontent is the first necessity of progress. - Edison
  6. #4
  7. No Profile Picture
    Problem Solver
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2001
    Stockholm, Sweden
    Rep Power
    Originally Posted by tintumon
    What do y'all think? I've always wondering if databases are a bit over kill for small amounts of data being stored.
    The key word is "small amounts".
    The problem with storing things in text files is that you don't have any indexes, so to retrieve a certain piece of information you need to loop through the data in these files to find it. This time increases linearly with the amount of data, while with a database you can have indexes where the search time for a specific record is O (log(n)) and although you have a higher overhead with a database (connecting, parsing the query, etc) this search time is much smaller when the size of the stored data increases.

    As for storing it in XML, well there might be some occasions when this is advantageous but generally I would say that parsing XML requires just too much performance, so I would think twice about it, OTOH if you don't want to store it in a database then you probably have a very small site with few visitors and then performance is probably not a concern.

    So yes, for small amounts of data you can store it in a text file, but pretty soon a database becomes the better solution.

    Comments on this post

    • mateoc15 agrees

IMN logo majestic logo threadwatch logo seochat tools logo