我已经做了一个小的演示网站,我在sql server上的一个图像列中存储图像。我有几个问题…

这是个坏主意吗? 当它增长时,它会影响我的站点的性能吗?

另一种方法是将图像存储在磁盘上,而仅在数据库中存储对图像的引用。这一定是很多人都遇到过的困境。我很欢迎你的建议,如果可以的话,我很乐意少犯一些错误。


当前回答

While performance issues are valid the real reasons in practice that you should avoid storing images in a database are for database management reasons. Your database will grow very rapidly and databases cost much more than simple file storage. Database backups and restores are much more expensive and time-consuming than file backup restores. In a pinch, you can restore a smaller database much more quickly than one bloated with images. Compare 1 TB of file storage on Azure to a 1 TB database and you'll see the vast difference in cost.

其他回答

当在SQL Server中存储图像时不使用'image'数据类型,根据MS的说法,它将在新版本的SQL Server中逐步淘汰。使用varbinary(max)代替

https://msdn.microsoft.com/en-us/library/ms187993.aspx

2012年发布了另一个选项,名为文件表:https://msdn.microsoft.com/en-us/library/ff929144.aspx

我曾经陷入过这样的困境,并在谷歌上进行了大量的研究以寻求意见。我发现,对于较大的图像,许多人确实认为将图像保存到磁盘更好,而mySQL允许更容易的访问,特别是从PHP等语言访问。

我发现了一个类似的问题

MySQL BLOB vs文件存储小PNG图像?

我的最终结论是,对于个人资料图片这样的东西,每个用户都需要一个小的方形图像,mySQL会比在硬盘上存储一堆拇指更好,而对于相册和类似的东西,文件夹/图像文件更好。

希望能有所帮助

While performance issues are valid the real reasons in practice that you should avoid storing images in a database are for database management reasons. Your database will grow very rapidly and databases cost much more than simple file storage. Database backups and restores are much more expensive and time-consuming than file backup restores. In a pinch, you can restore a smaller database much more quickly than one bloated with images. Compare 1 TB of file storage on Azure to a 1 TB database and you'll see the vast difference in cost.

根据我的经验,将存储在另一个位置的图像存储到url是简单项目的最佳方式。