Possible Duplicate:
Storing Images in DB - Yea or Nay?
Images in database vs file system可能重复:在DB中存储图像 - 是或否?数据库与文件系统中的映像
I've been developing a web application using RIA technologies (Flex + PHP + MySQL + Ajax) and now I'm in a dilemma about image files.
我一直在使用RIA技术(Flex + PHP + MySQL + Ajax)开发Web应用程序,现在我处于图像文件的两难境地。
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:
我在我的Flex应用程序中使用了一些图像,因此我认为“如果我将它们存储到数据库中,然后从中检索它可能会很棒;然后,维护过程应该更容易”。但是,这是我的困境:
Should I store the physical URL of my images, or is going to be better if I store directly the image?
我应该存储我的图像的物理URL,还是如果我直接存储图像会更好?
For example, should my Cars
table looks like:
例如,我的汽车表应该是这样的:
ID
(autonumeric) |Source
(text)ID(自动数字)|来源(文字)
or like this?
或者像这样?
ID
(autonumeric) |Image
(longblob or blob)ID(自动数字)|图像(longblob或blob)
I know that here are cool people that can answer me this question, explaining me which is better and why :)
我知道这里有很酷的人可以回答我这个问题,向我解释哪个更好,为什么:)
6 个解决方案
#1
6
I personally recommend to Store Images in the database. Of course it both advantages and disadvantages.
我个人建议将图像存储在数据库中。当然它既有利也有弊。
Advantages of storing BLOB data in the database:
在数据库中存储BLOB数据的优点:
- It is easier to keep the BLOB data synchronized with the remaining items in the row.
- BLOB data is backed up with the database. Having a single storage system can ease administration.
- BLOB data can be accessed through XML support in MySQL, which can return a base 64–encoded representation of the data in the XML stream.
- MySQL Full Text Search (FTS) operations can be performed against columns that contain fixed or variable-length character (including Unicode) data. You can also perform FTS operations against formatted text-based data contained within image fields—for example, Microsoft Word or Microsoft Excel documents.
保持BLOB数据与行中的其余项目保持同步更容易。
BLOB数据与数据库一起备份。拥有单一存储系统可以简化管理。
可以通过MySQL中的XML支持访问BLOB数据,该支持可以返回XML流中数据的基本64位编码表示。
可以对包含固定或可变长度字符(包括Unicode)数据的列执行MySQL全文搜索(FTS)操作。您还可以对图像字段中包含的格式化基于文本的数据执行FTS操作 - 例如,Microsoft Word或Microsoft Excel文档。
Disadvantages of Storing BLOB Data in the Database:
在数据库中存储BLOB数据的缺点:
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:
仔细考虑哪些资源可以更好地存储在文件系统而不是数据库中。很好的例子是通常通过HTTP HREF引用的图像。这是因为:
- Retrieving an image from a database incurs significant overhead compared to using the file system.
- Disk storage on database SANs is typically more expensive than storage on disks used in Web server farms.
与使用文件系统相比,从数据库中检索图像会产生很大的开销。
数据库SAN上的磁盘存储通常比Web服务器场中使用的磁盘上的存储更昂贵。
#2
4
As a general rule you wan't to keep your databases small, so they perform better (and backup better too). So if you can store only a filesystem reference (path + filename) or URL in the DB, that would be better.
作为一般规则,您不要让数据库保持较小,因此它们的性能更好(并且备份也更好)。因此,如果您只能在数据库中存储文件系统引用(路径+文件名)或URL,那就更好了。
#3
3
Its probably a question of personal preference.
这可能是个人偏好的问题。
As a general rule its better to keep the database small. However when you come to enterprise applications they regulary add the images directly to the database. If you place them on the file system the db and your file system can get out of sync.
作为一般规则,最好保持数据库小。但是,当您进入企业应用程序时,他们会定期将映像直接添加到数据库中。如果将它们放在文件系统上,则db和文件系统可能会不同步。
Larger CMS will regulary place those files in the db. However be aware that this requires a larger DB sizing when everything is growing...
较大的CMS会定期将这些文件放在数据库中。但请注意,当一切都在增长时,这需要更大的数据库大小...
When you are saving the url and name only, be sure that these won't change in the future.
当您仅保存网址和名称时,请确保以后不会更改这些网址和名称。
With files stored in the database you can implement security easier and you don't have to worry about duplicate filenames.
使用存储在数据库中的文件,您可以更轻松地实现安全性,而不必担心重复的文件名。
#4
1
I used to store the path into the URL, but then adding an additional web server to the mix proved less than ideal. For one thing, you'll have to share the path to where the images are stored. We were using NFS and it became slow after a while. We tried syncing the files from one web server to another but the process became cumbersome.
我曾经将路径存储到URL中,但随后在混合中添加额外的Web服务器被证明不太理想。首先,您必须共享存储图像的路径。我们使用的是NFS,一段时间后变得很慢。我们尝试将文件从一个Web服务器同步到另一个Web服务器,但这个过程变得很麻烦。
Having said that, I would store them in the DB. I've since moved all my image/file storage over to MongoDB. I know this doesn't satisfy your needs but we've tried it all (even S3) and we weren't happy with the other solutions. If we had to, I would definite throw them inside MySQL.
话虽如此,我会将它们存储在数据库中。我已经将我的所有图像/文件存储移动到MongoDB。我知道这不能满足您的需求,但我们已经尝试过(甚至是S3),我们对其他解决方案并不满意。如果必须,我肯定会把它们扔进MySQL。
#5
0
I'd store the url, it's less data and that means a smaller database and faster data fetching from it ;)
我存储了url,它的数据更少,这意味着数据库更小,从中获取更快的数据;)
#6
0
Personally, I've always stored the URL.
就个人而言,我总是存储URL。
There's no real reason not to store the image directly in the database, but there are benefits to not storing it in the database.
没有真正的理由不将图像直接存储在数据库中,但不将其存储在数据库中会有好处。
You get more flexibility when you don't store the image in the database. You can easily move it around and just update the URL in the file. So, if you wanted to move the image from your webserver to a service such as Flickr or Amazon Web Services, it would just be as easy as updating the link to the new files. That also gives you easy access to content delivery networks so that the images are delivered to end users quicker.
如果不将图像存储在数据库中,则可以获得更大的灵活性。您可以轻松移动它,只需更新文件中的URL。因此,如果您想将图像从Web服务器移动到Flickr或Amazon Web Services等服务,那么就像更新新文件的链接一样简单。这也使您可以轻松访问内容交付网络,以便更快地将图像传送给最终用户。
#1
6
I personally recommend to Store Images in the database. Of course it both advantages and disadvantages.
我个人建议将图像存储在数据库中。当然它既有利也有弊。
Advantages of storing BLOB data in the database:
在数据库中存储BLOB数据的优点:
- It is easier to keep the BLOB data synchronized with the remaining items in the row.
- BLOB data is backed up with the database. Having a single storage system can ease administration.
- BLOB data can be accessed through XML support in MySQL, which can return a base 64–encoded representation of the data in the XML stream.
- MySQL Full Text Search (FTS) operations can be performed against columns that contain fixed or variable-length character (including Unicode) data. You can also perform FTS operations against formatted text-based data contained within image fields—for example, Microsoft Word or Microsoft Excel documents.
保持BLOB数据与行中的其余项目保持同步更容易。
BLOB数据与数据库一起备份。拥有单一存储系统可以简化管理。
可以通过MySQL中的XML支持访问BLOB数据,该支持可以返回XML流中数据的基本64位编码表示。
可以对包含固定或可变长度字符(包括Unicode)数据的列执行MySQL全文搜索(FTS)操作。您还可以对图像字段中包含的格式化基于文本的数据执行FTS操作 - 例如,Microsoft Word或Microsoft Excel文档。
Disadvantages of Storing BLOB Data in the Database:
在数据库中存储BLOB数据的缺点:
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:
仔细考虑哪些资源可以更好地存储在文件系统而不是数据库中。很好的例子是通常通过HTTP HREF引用的图像。这是因为:
- Retrieving an image from a database incurs significant overhead compared to using the file system.
- Disk storage on database SANs is typically more expensive than storage on disks used in Web server farms.
与使用文件系统相比,从数据库中检索图像会产生很大的开销。
数据库SAN上的磁盘存储通常比Web服务器场中使用的磁盘上的存储更昂贵。
#2
4
As a general rule you wan't to keep your databases small, so they perform better (and backup better too). So if you can store only a filesystem reference (path + filename) or URL in the DB, that would be better.
作为一般规则,您不要让数据库保持较小,因此它们的性能更好(并且备份也更好)。因此,如果您只能在数据库中存储文件系统引用(路径+文件名)或URL,那就更好了。
#3
3
Its probably a question of personal preference.
这可能是个人偏好的问题。
As a general rule its better to keep the database small. However when you come to enterprise applications they regulary add the images directly to the database. If you place them on the file system the db and your file system can get out of sync.
作为一般规则,最好保持数据库小。但是,当您进入企业应用程序时,他们会定期将映像直接添加到数据库中。如果将它们放在文件系统上,则db和文件系统可能会不同步。
Larger CMS will regulary place those files in the db. However be aware that this requires a larger DB sizing when everything is growing...
较大的CMS会定期将这些文件放在数据库中。但请注意,当一切都在增长时,这需要更大的数据库大小...
When you are saving the url and name only, be sure that these won't change in the future.
当您仅保存网址和名称时,请确保以后不会更改这些网址和名称。
With files stored in the database you can implement security easier and you don't have to worry about duplicate filenames.
使用存储在数据库中的文件,您可以更轻松地实现安全性,而不必担心重复的文件名。
#4
1
I used to store the path into the URL, but then adding an additional web server to the mix proved less than ideal. For one thing, you'll have to share the path to where the images are stored. We were using NFS and it became slow after a while. We tried syncing the files from one web server to another but the process became cumbersome.
我曾经将路径存储到URL中,但随后在混合中添加额外的Web服务器被证明不太理想。首先,您必须共享存储图像的路径。我们使用的是NFS,一段时间后变得很慢。我们尝试将文件从一个Web服务器同步到另一个Web服务器,但这个过程变得很麻烦。
Having said that, I would store them in the DB. I've since moved all my image/file storage over to MongoDB. I know this doesn't satisfy your needs but we've tried it all (even S3) and we weren't happy with the other solutions. If we had to, I would definite throw them inside MySQL.
话虽如此,我会将它们存储在数据库中。我已经将我的所有图像/文件存储移动到MongoDB。我知道这不能满足您的需求,但我们已经尝试过(甚至是S3),我们对其他解决方案并不满意。如果必须,我肯定会把它们扔进MySQL。
#5
0
I'd store the url, it's less data and that means a smaller database and faster data fetching from it ;)
我存储了url,它的数据更少,这意味着数据库更小,从中获取更快的数据;)
#6
0
Personally, I've always stored the URL.
就个人而言,我总是存储URL。
There's no real reason not to store the image directly in the database, but there are benefits to not storing it in the database.
没有真正的理由不将图像直接存储在数据库中,但不将其存储在数据库中会有好处。
You get more flexibility when you don't store the image in the database. You can easily move it around and just update the URL in the file. So, if you wanted to move the image from your webserver to a service such as Flickr or Amazon Web Services, it would just be as easy as updating the link to the new files. That also gives you easy access to content delivery networks so that the images are delivered to end users quicker.
如果不将图像存储在数据库中,则可以获得更大的灵活性。您可以轻松移动它,只需更新文件中的URL。因此,如果您想将图像从Web服务器移动到Flickr或Amazon Web Services等服务,那么就像更新新文件的链接一样简单。这也使您可以轻松访问内容交付网络,以便更快地将图像传送给最终用户。