-1

i want to get a better idea about storing images in a database. mostly around the performance.

i want to have a database of images. i know that it would be inefficient for querying if it had many fields to search through, but how would performance be impacted if i kept the images in a separate table (table with imageID and Image only). so that when querying the table i could use the main table, but i would only pull back the images from the images table when i need to.

of course this is bad practice and the ideal would be to keep the image in a directory and store that image's filepath in the database.

remember the filepath (string variable) that refers to the image location will likely be longer than the imageID.

it makes sense that it would be quicker to search though the database for database related images, rather than jumping between database and host directory.

what do you guys think?

X0r0N
  • 1,816
  • 6
  • 29
  • 50

1 Answers1

1

Depending on your application goal will decide which method of storage/retrieval is best. No one blanket solution fits all needs.

The two primary ways of storing user-uploaded images are either putting the binary content into the database as a BLOB, or storing the images into the file-systems.

The facts are the method of binary storage is very successful and has many advantages over file system storage. Some advantages are:

Referential integrity (ACID Consistency)

Ease of backup

Saving of Inodes

Easy categorisation

No Name collisions

Storage of Meta Data (data about data)

Central point of operations

Replication over multiple servers

Placing the images in the database has the advantage of not requiring any sort of filesystem permissions on the webserver, and removes any sort of syncing issues if you're serving up the site off of multiple webservers. However, over time it makes your database huge, and if you don't design your tables correctly, it can absolutely kill your performance and scalability.

There are also several reasons not to store images or other binary data in a database.

Better caching

External proxies

MySQL can store 'normal" data better

Data through-put is higher with the filesystem

Speed of retrieval

REFER: Storing images with MySQL and StackOverflow Question

Community
  • 1
  • 1
Rumin
  • 3,787
  • 3
  • 27
  • 30