将图像存储在数据库或文件系统中 [英] Store images in database or on file system

查看:157
本文介绍了将图像存储在数据库或文件系统中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在DB中存储图片 - 是或否?

在文件系统中存储图像更快,更可靠,或者应该将它们存储在数据库中吗?

Is it faster and more reliable to store images in the file system or should I store them in a database?

假设图像不大于200 MB。目标是快速,可靠的访问。

Let's say the images will be no larger than 200 MB. The objective is fast, reliable access.

一般来说,人们如何决定在文件系统或数据库中存储文件(例如图像,PDF) / p>

In general, how do people decide between storing files (e.g., images, PDFs) in the file system or in the database?

推荐答案

个人意见:我总是在文件系统上存储图像,并且只在数据库中存储文件路径。在许多情况下,数据库存储在快速(读取:昂贵的存储,15k RPM或SSD驱动器)存储。图像或其他文件,通常可以存储在较慢的(读取:更便宜,更大的驱动器,7.2k RPM驱动器)存储。

Personal opinion: I ALWAYS store images on the file system, and only store a filepath in the database. In many situations, databases are stored on fast (read: expensive storage, 15k RPM or SSD drives) storage. Images or other files, typically can be stored on slower (read: cheaper, larger drives, 7.2k RPM drives) storage.

我发现这是最好的,因为它允许数据库保持较小的大小。通常,数据库很好地存储数据。它们可以快速搜索和检索小比特的数据。文件系统很好地存储文件,它们被优化以快速地找到和检索较大比特的数据。

I find this to be the best, since it allows for the database to remain small in size. In general, databases store "data" well. They can search and retrieve small bits of data fast. File Systems store "files" well, they are optimized to find and retrieve larger bits of data fast.

显然,这两种方法都有折衷,成为一个尺寸适合所有;然而,可能有一些使用情况下,在数据库中存储图像是一件好事,如果他们都很小,你不预期非常多,并且你的数据库是在同一存储介质上的文件共享,那么将图像直接放入数据库可能是有意义的。

Obviously there are tradeoffs to both approaches, and there isn't going to be a one-size fits all; however, there may be some use cases where storing images in the database is a good thing, if they are all quite small, and you don't anticipate very many of them, and your database is on the same storage medium as your file share, then it probably makes sense to drop the images directly into the database.

另外,SQL Server 2008R2有一个FileStream字段类型,它可以提供最好的两个世界,我还没有使用它,所以我不能说它是如何工作。

As a side note, SQL Server 2008R2 has a FileStream field type, which can provide the best of both worlds, I have not used it yet, so I can't speak to how well it works.

这篇关于将图像存储在数据库或文件系统中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆