views:

145

answers:

3

The best way to store images into MySQL is by storing the image location as a charater string.

If you need to manipulate the image, then, the best way is to copy the image as a binary.

How one can store images into binary form and how we can retrive them back? I don’t know anything about this technique. Please tell me how we can do this.

+5  A: 

Don't store images in the database. Store them in the filesystem, then store their relative paths in the database.

Ignacio Vazquez-Abrams
A: 

You can use the BLOB data type. Although I agree with @Ignacio Vazquez-Abrams, there are times where storing the image in the DB is best. I have done so in past with great results. As long as the files are not large then this is a good solution.

Dustin Laine
+1  A: 

I've written some blogs on this (and have some data from SQL Server)

http://www.atalasoft.com/cs/blogs/loufranco/archive/2007/12/03/images-in-databases-part-i-what-to-store.aspx

http://www.atalasoft.com/cs/blogs/loufranco/archive/2007/12/04/images-in-databases-part-ii-web-images-are-random-access.aspx

http://www.atalasoft.com/cs/blogs/loufranco/archive/2009/10/26/more-on-images-in-databases.aspx

Basically,

  1. Small images are ok to put in a blob
  2. Large images are much better to put on the filesystem
  3. Images in a blob are much easier to manage (transactions, backup, simpler code, access control)
  4. Images on the filesystem will perform much better
  5. Think about pulling some meta-data out of the image and storing in separate columns for filtering and sorting purposes.

Almost every professional enterprise system that needs to deal with a lot of large blobs has some way of putting them on the filesystem. The latest SQL Server even has a field type that will do it automatically (and then it's as easy to program and manage as a blob)

Lou Franco