00 Votes

Storing Images in MySQL-Database or on WebSpace - Advantages and Disadvantages

Question by Guest | 2015-05-05 at 13:04

At the moment, I am trying to create an entirely reworked website, so it is time to throw away old habits.

One of my old habits was to always and only store images on the web space respectively the file system of the server and never within a database.

However, as I have heard, it is also possible to directly save images using BLOB within a MySQL database and to retrieve them therefrom. But, should I do that? Which advantages and disadvantages are there? What about the performance? Or is my idea stupid and I should not consider this at all?

ReplyPositiveNegative
0Best Answer0 Votes

In general, I would not recommend to store images within a database. Instead, I would always prefer the filesystem.

Of course, it always depends on the individual case, and of course, there are surely situations in which there are also arguments for storing in databases. Here are some considerations:

  • Performance: If the database is nevertheless charged through complicated queries, you can save performance and win speed if the database does not have to care about the images as additional task. Additionally, the file systems are optimized for rapid file access, this advantage does not apply for databases.
  • Webspace-Storage is cheaper than Database-Storage: Many web space provider are limiting the size of databases while the amount of hard disk webspace is growing more and more. With this in mind, it makes no sense to write things into the database that could also be stored on the webspace.
  • Programming: The PHP programming as a well as the HTML coding is easier if the images are fetched from the file system. With this, you do not need any additional code to read out and stream the image from the database.
  • Style: Databases should stay slim and they should only contain structured data, no binary data.

The only real advantage for the database is, that the data stay together (for example profile photos and profile data). This is a benefit for searching as well as for sharing and backup of the data.

When separating those things, you have to care about a corresponding link in the database (for example an additional column containing the filename or with renaming the images with the primary key from the database). When renaming one of the parts, it is hard to maintain the connection. You do not have this problem when storing the data together only in the database.
2015-05-05 at 15:06

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.