Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store image files or URLs in MySQL database? Which is better? [duplicate]

Possible Duplicate:
Storing Images in DB - Yea or Nay?
Images in database vs file system

I've been developing a web application using RIA technologies (Flex + PHP + MySQL + Ajax) and now I'm in a dilemma about image files.

I use some images in my Flex app, so I think "it could be awesome if I store them into database, and then retrieve from it; consecuently, maintain process should be more easy". But, here is my dilemma:

Should I store the physical URL of my images, or is going to be better if I store directly the image?

For example, should my Cars table looks like:

ID (autonumeric) | Source (text)

or like this?

ID (autonumeric) | Image (longblob or blob)

I know that here are cool people that can answer me this question, explaining me which is better and why :)

like image 347
Fran Verona Avatar asked Nov 18 '11 12:11

Fran Verona


People also ask

Is it good practice to store images in MySQL?

Another way to store an image in the MySQL database is to store it in the table itself. Images size can be quite big, sometimes bigger than 1 or 2MB. So, storing images in a database can put additional load on your database and the network between your database and your web server if they're on separate hosts.

What is the best way to store images in a database?

Answers. Hi, These two ways are both ok. My suggestion is to store images into sql database if there are no much more images, otherwise, it's better store them into file system because you can store them no matter how many there are.

Is it better to store images in database or filesystem?

Generally databases are best for data and the file system is best for files. It depends what you're planning to do with the image though. If you're storing images for a web page then it's best to store them as a file on the server. The web server will very quickly find an image file and send it to a visitor.

Is it good practice to save image in database?

While you can save images in a DB, that's only a good idea if the image is small and you have only a few of them.


1 Answers

I personally recommend to Store Images in the database. Of course it both advantages and disadvantages.

Advantages of storing BLOB data in the database:

  • It is easier to keep the BLOB data synchronized with the remaining items in the row.
  • BLOB data is backed up with the database. Having a single storage system can ease administration.
  • BLOB data can be accessed through XML support in MySQL, which can return a base 64–encoded representation of the data in the XML stream.
  • MySQL Full Text Search (FTS) operations can be performed against columns that contain fixed or variable-length character (including Unicode) data. You can also perform FTS operations against formatted text-based data contained within image fields—for example, Microsoft Word or Microsoft Excel documents.

Disadvantages of Storing BLOB Data in the Database:

Carefully consider what resources might be better stored on the file system rather than in a database. Good examples are images that are typically referenced via HTTP HREF. This is because:

  • Retrieving an image from a database incurs significant overhead compared to using the file system.
  • Disk storage on database SANs is typically more expensive than storage on disks used in Web server farms.
like image 138
ScoRpion Avatar answered Sep 24 '22 11:09

ScoRpion