What is the best way to store Binary data (images, pdf's, mp3's, videos ect) in mysql and why? What i would love to know is how you do it(as developers) and why? Also how the big sites do it?
Thank you in advance ;-)
Binary data can be stored in a table using the data type bytea or by using the Large Object feature which stores the binary data in a separate table in a special format and refers to that table by storing a value of type oid in your table.
Of course you can. But database including MySQL is not good at storing unstructured data like pictures, video, mp3, etc. If you just store a few small files ,it's OK, but if you want to scale out to store a lot of files, you should chose another way.
A Binary Large Object ( BLOB ) is a MySQL data type that can store binary data such as images, multimedia, and PDF files.
Binary data is a type of data that is represented or displayed in the binary numeral system. Binary data is the only category of data that can be directly understood and executed by a computer. It is numerically represented by a combination of zeros and ones.
To store Binary data in MySQL Blob can be used: MySQL Manuel: 10.4.3. The BLOB and TEXT Types
Although if it isn't really necessary I wouldn't store binary data in a database, because the central reasons for storing data in MySQL etc. (like Join, Index, ...) can hardly be used with this data types. Blob also is degrading the overall database performance.
Perhaps you build a separate table for files where you store several aspects and a filesystem path...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With