If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Should I store images in the db or in a folder?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-09-10, 06:25
johnnyt74 johnnyt74 is offline
Registered User
 
Join Date: Jul 2010
Posts: 9
Should I store images in the db or in a folder?

Hi all,
While browsing some php code yesterday I found out that it was possible to store images in a database in the form of 'blobs'.

I currently have a website that allows members to upload a profile picture of themselves. The pictures are renamed with a time/date hash and the link to the users picture is stored in the database. The actual thumbnail itself is stored as a jpg in a folder.

My question is this...
From a scaleability point of view, is this the right way to be doing this? I currently have around 1500 members with about 50 new ones joining every day. The site is really beginning to take off and I'm wondering whether a better way would be to store the pictures themselves in the database?

What are the pro's and con's of this??

I notice in myPhpAdmin that it will only allow me to export/import a max of 50Mb so I'm thinking that this would be used up a lot quicker if I store images in the database.

However, I'm also unsure of how many images I can hold in the folder and what effect, say, 50,000 or 500,000 images would have in one folder??

Can anyone give me any advice on the best solution for this?

I wondered how facebook do it as they have obviously got millions of user profile pictures to deal with....??

Many thanks for any help you can give me

Cheers

John
Reply With Quote
  #2 (permalink)  
Old 07-09-10, 06:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
it's a pretty safe bet that facebook does not store images in a database

nor should you

as for pros/cons, the only pro is that your images are backed up automatically along with your database -- but then, taking a database backup will be slower

one thing's for certain, if you're thinking about scalability, you'll want to develop some better tools thatn phpmyadmin
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-09-10, 06:54
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
A couple of years ago someone actually did some research whether to store images (blobs) in the database or not and the outcome was quite interesting I think.

The bottom line of that research:
Quote:
Originally Posted by Russell Sears, Catharine Van Ingen, and Jim Gray
The study indicates that if objects are larger than one megabyte on average, NTFS has a clear advantage over SQL Server. If the objects are under 256 kilobytes, the database has a clear advantage.
I have no idea to which extend this can be "transferred" to other databases. But I think the general conclusion is probably similar with other DBMS. The size of the blobs will most definitely change when using a different DBMS and/or filesystem

Here is the link:
To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem - Microsoft Research
Reply With Quote
  #4 (permalink)  
Old 07-09-10, 11:55
johnnyt74 johnnyt74 is offline
Registered User
 
Join Date: Jul 2010
Posts: 9
Some great replies there. Thanks to r937 and shammat.

I think I'll just stick with the method I use now. The images are only around 10K so they could go in a database but for the extra hassle and the negligible benefits I think the system I have at the moment is fine.

Thanks again for your wise words and input. It is very much appreciated.

Cheers

John
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On