# Its ok to store image sized files into mysql isn't it?

**URL:** <https://www.ruby-forum.com/t/its-ok-to-store-image-sized-files-into-mysql-isnt-it/145281>\
**Category:** Rails\
**Created:** [August 7, 2008, 2:18pm UTC](https://www.ruby-forum.com/t/its-ok-to-store-image-sized-files-into-mysql-isnt-it/145281 "2008-08-07T14:18:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [August 7, 2008, 2:18pm UTC](https://www.ruby-forum.com/t/its-ok-to-store-image-sized-files-into-mysql-isnt-it/145281/1 "2008-08-07T14:18:50Z")

</div>

Hi,

Can I assume for a web app with low number of users it’s OK to store  
image  
files in the mysql database? Makes it easy to setup/back etc then.  
Perhaps this is how the plugins like upload\_fu work (i.e. upload  
straight to  
the database?).

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [August 7, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/its-ok-to-store-image-sized-files-into-mysql-isnt-it/145281/2 "2008-08-07T19:59:58Z")

</div>

> Can I assume for a web app with low number of users it’s OK to store  
> image  
> files in the mysql database? Makes it easy to setup/back etc then.  
> Perhaps this is how the plugins like upload\_fu work (i.e. upload  
> straight to  
> the database?).

Sure it’s okay. You just want to run some numbers first to make sure  
you won’t run out of room and your DBA won’t get upset that his  
database is getting too big, etc.

I’d also suggest caching the results of your image generation action  
to disk so you don’t hammer on Rails unnecessarily.

-philip

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [August 7, 2008, 9:38pm UTC](https://www.ruby-forum.com/t/its-ok-to-store-image-sized-files-into-mysql-isnt-it/145281/3 "2008-08-07T21:38:56Z")

</div>

One distinct advantage of storing the image in the database is when  
you outgrow one server box and need to run instances on several boxes.  
A file based storage mechanism would have to somehow serve the images  
to multiple boxes. As for me, if the image data is relatively small  
(like thumbnails or avatars) I think storing them in the database is  
convenient.

However, when I do this I put the image data into a separate table  
(like pictures) so that I can easily restrict the fetch of the image.  
You don’t want to be fetching all that binary data just to get a list  
of people, for example. Then on your view when you show an individual  
user, then go get the image from the pictures table for that user.

There are, however, other ways to do this, but you just have to decide  
if you need to take that extra effort to keep your images out of the  
database.

> I’d also suggest caching the results of your image generation action  
> to disk so you don’t hammer on Rails unnecessarily.

Or maybe even memcached possibly?
