0

There are a lot of questions on SO about storing images with MySQL (or any other RDBMS). Some examples:

Nearly all answers recommend to store images as files and only have the filesystem path in the database itself, for various reasons. But the problem with this solution is that the database no longer can enforce data integrity for the images. In one answer though, there's a hint that data integrity could be achieved even when the images are stored as files.

One solution I could imagine is using something like inotify to watch the directory with the image files and call some stored procedure to react to the changes inotify reported. But that isn't a solution where the database itself would guarantee integrity.

Is there any other way to synchronize and enforce integrity between file paths stored in MySQL and the files in the filesystem?

z80crew
  • 1,150
  • 1
  • 11
  • 20
  • 1
    *Is there any other way to synchronize and enforce integrity between file paths stored in MySQL and the files in the filesystem?* No. MySQL does not interacts with filesystem by such way. – Akina Oct 28 '20 at 12:48
  • 1
    If you can, just store them in the database. That isn't wrong as some people might suggest. Storing the files in the file system might give minor performance benefit and might be easier to access when programming an application. But as you figured out, there are (severe) problems that come with that approach, like not being able to enforce integrity. – sticky bit Oct 28 '20 at 12:48
  • 1
    I think that you may simply set the filesystem attributes to those which does not allow to manipulate the files - no rename/edit/delete, only save or retrieve. Only special service tool can clean the directory from the files which have no reference in the database. – Akina Oct 28 '20 at 12:51

0 Answers0