3

I know these question is one of the frequently asked, but I need your help for a specific case.

I am developing an application, where some users can add orders, and some users can perform these orders. These orders are very specific, so only limited number of users can add them.

Than, three documents are generated for each order. The size of each document doesn't exceed 1MB so I am going to save them in my DB as blobs, but I don't know what will happen in the future, the size of the documents may be significantly increase (for example: 5MB). What should I do? and Why? Save them as blobs or save them as file path.

For example: Is it good practice to keep saving 5MB files as blobs in DB, or is it better to save them as file path from the beginning(If I know this can happen ), or save them as blobs and if they increase than change it.

For this project I am using digitalocean server.

Nika Kurashvili
  • 6,006
  • 8
  • 57
  • 123

1 Answers1

1

MySQL can handle 5MB blobs. If you use MEDIUMBLOB it can handle up to 16MB, and if you use LONGBLOB it can handle up to 4GB. Read String Type Overview for details.

Other than this, the same pros and cons apply for putting BLOB data into the database.

  • Lots of BLOB data makes the database much larger of course.
  • Keeping all the data together means a single database backup includes all the data including "attachments".
  • Putting BLOBs in the database means the BLOB data supports transaction isolation, rollback, SQL privileges, etc. If you DELETE some rows, it also deletes the BLOBs on those rows, but external files are not deleted automatically.
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828