Question

I don't know this concept is there or not. Can we store the Files and related information in MySQL database ? If the answer is Yes then how ?

Was it helpful?

Solution

Yes, but make sure you really want to.

MySQL has a "BLOB" (and related) column type, which can be used for storing arbitrary binary data, much the same way you would store a string (it is just a string of bits instead of a string a characters) value.

The problem is serving files from the database is quite inefficient (the filesystem is much faster), as well as putting unnecessary strain on your DB. So if you can, you are often better of using real files and only storing metadata in the database. Or, at a minimum caching the file to the filesystem.

OTHER TIPS

You can store the contents of a file in a BLOB but it is often better to just store the location of the file as a varchar and store the actual contents of the file in the filesystem.

If the answer is Yes then why?
Filesystem itself is already a database. A very good one. To deal with files, keyed by filenames.
While relational databases, like mysql, intended to deal with data contents - order it, filter it, make relations with it. Nothing of this can be done to binary file content. You have to have strong reasons to put files into relational database. Not "why not?" one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top