Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to store media files on a database?

I want to store a large number of sound files in a database, but I don't know if it is a good practice. I would like to know the pros and cons of doing it in this way.

I also thought on the possibility to have "links" to those files, but maybe this will carry more problems than solutions. Any experience in this direction will be welcome :)

Note: The database will be MySQL.

like image 625
David Ameller Avatar asked Sep 30 '08 19:09

David Ameller


People also ask

Which database is used for media?

Media database platforms (Cision, Meltwater, Muck Rack) have been created to help. These are platforms that include a database of multiple types of “influencers”–journalists, bloggers, analysts, columnists and more and the “beats” or markets that they cover.

Which database is best for storing files?

Notice that these days most DB (and RDBMS such as PostGreSQL or MySQL and non-SQL DBMS such as MongoDB) are storing their data in files (that is, using raw disk partitions for the storage of DB has become out of fashion).


1 Answers

Every system I know of that stores large numbers of big files stores them externally to the database. You store all of the queryable data for the file (title, artist, length, etc) in the database, along with a partial path to the file. When it's time to retrieve the file, you extract the file's path, prepend some file root (or URL) to it, and return that.

So, you'd have a "location" column, with a partial path in it, like "a/b/c/1000", which you then map to: "http://myserver/files/a/b/c/1000.mp3"

Make sure that you have an easy way to point the media database at a different server/directory, in case you need that for data recovery. Also, you might need a routine that re-syncs the database with the contents of the file archive.

Also, if you're going to have thousands of media files, don't store them all in one giant directory - that's a performance bottleneck on some file systems. Instead,break them up into multiple balanced sub-trees.

like image 150
Mark Bessey Avatar answered Oct 08 '22 10:10

Mark Bessey