Mysql – hosting images on own database or 3rd party

database-designMySQL

I'm working on an app where the user can upload 1-6 pictures.

I've never handled images&databases before so I wanted to know if there is anything in particular I should be careful of.

Also, I've read that images are data intensive, and was wondering whether or not I should host them on the same database as my other data. Or if I should create an entirely different database for them.

thanks

Best Answer

The most common solution is, as commented by @Akina, to store images in the file system, and just store some kind of reference (file path or similar) in the database that allows you to uniquely identify the image in the file system.

However, there are also use cases where it makes sense to store the images directly in the database. Maybe you don't have permissions to store files on the file system. Maybe you have a lot of RAM and you don't expect the images to take up all that much space, and putting the files in the database means you only have to backup the database and not have to worry about a separate backup of the file system.

One of the big disadvantages of storing the images in the database is obviously that they can make your database grow to an unmaintainable size where backups take a long time and you may have to take special steps to avoid disrupting users (i.e. to avoid locking) for very long while running the backup. Maybe you can also no longer fit the whole database in RAM, which will lead to slowness. In addition, images usually require BLOB columns, and these come with their own set of disadvantages.

Related Question