在MySQL数据库中存储图像文件或URL?哪个更好?
我一直在开发使用RIA技术(Flex + PHP + MySQL + Ajax)的Web应用程序,现在我在图像文件中处于困境。
I've been developing a web application using RIA technologies (Flex + PHP + MySQL + Ajax) and now I'm in a dilemma about image files.
我使用一些我的Flex应用程序中的图像,所以我认为如果我将它们存储到数据库中,那么可能会很棒,然后从中检索出来,请务必保持过程更容易。但是,这是我的困境:
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:
我应该存储我的图像的物理URL,还是直接存储图像会更好? strong>
Should I store the physical URL of my images, or is going to be better if I store directly the image?
例如,如果我的 Cars
表格如下所示:
For example, should my Cars
table looks like:
ID
(autonumeric)|来源
(文字)
ID
(autonumeric) |Source
(text)
或这样?
ID
(autonumeric)|图像
(longblob或blob)
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 :)
我个人建议将图像存储在数据库中。
I personally recommend to Store Images in the database. Of course it both advantages and disadvantages.
在数据库中存储BLOB数据的优点:
Advantages of storing BLOB data in the database:
- 将BLOB数据与该行中剩余的项目保持同步更容易。
- 使用数据库备份BLOB数据。拥有单个存储系统可以减轻管理。
- 可以通过MySQL中的XML支持访问BLOB数据,可以在XML流中返回数据的基本64编码表示。 li>
- 可以对包含固定或可变长度字符(包括Unicode)数据的列执行MySQL全文搜索(FTS)操作。您还可以对图像字段中包含的基于格式的基于文本的数据执行FTS操作,例如Microsoft Word或Microsoft Excel文档。
在数据库中存储BLOB数据的缺点:
Disadvantages of Storing BLOB Data in the Database:
仔细考虑一下资源可能更好地存储在文件系统而不是数据库中。很好的例子是通常通过HTTP HREF引用的图像。这是因为:
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:
- 与使用文件系统相比,从数据库检索图像会导致相当大的开销。
- 数据库SAN上的磁盘存储通常比在Web服务器场中使用的磁盘上的存储更昂贵。