0

I am creating an application where users will post texts. Currently I am creating the text files of that texts post but i am not sure if storing it to MySql table is good or creating a txt file is good. .

Note: 1) There is no limit of the size of text post. Users may post a very big text or user me post containing only a letter.

2) There is no limit of post a user can upload.

Please Help Thank You. .

4 Answers4

0

Saving data into a file is more cost operation rather than in database.So its better to go for database.Because saving in file will do IO operation and this file I/O operation is really very costly in terms of computation and from OS perspectives.

Giriraj
  • 1
  • 3
  • Isn't there is any limit in storing large texts in a database?? – ankur bagla Sep 20 '14 at 08:36
  • Currently it's limited by [max_allowed_packet](https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_max_allowed_packet) size to 1 GB even if a longtext column could store more. – VMai Sep 20 '14 at 09:23
0

You should store it in the database instead of text file. There are many reasons for it. Go through this question for more descriptive answer. In short, you should choose database over files for security reason, speed, code maintainability and concurrency.

Community
  • 1
  • 1
user4055288
  • 551
  • 5
  • 11
0

You can use LOAD DATA INFILE to read the contents of a file and store it in a table in the database in a structured format.

LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;

You can also use largetext in mysql.But it would be slower and non-resilient.

Please check here

Community
  • 1
  • 1
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26
0

See there are some major things you should know before taking decision on where to save things

If the file is an image/Video/PDF
For this you should save the FILE NAME into the database and the image on server
If the file is a large text
For this you should save the file to the server as the database will not be able to take loads of text and many requests for long text at the same time and this will also save you space for more things in database
For any other thing, if you find it space consuming just save it on the server as this will give you space for database and more advantages