我可以在MySQL中存储图像吗? [英] Can I store images in MySQL

查看:76
本文介绍了我可以在MySQL中存储图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

MySQL中的图像

在MySQL中存储图像

我正在尝试开发一个网站,用户在注册时上传图片。我希望每个图像都应该有一个用PHP创建的拇指(这并不困难)。我想在数据库中保存拇指(因为它们非常小),我使用MySQL。 (我不想将拇指保存为驱动器上的物理文件。)

MySQL是否允许保存和检索图像数据,我该如何处理?如果它不支持图像数据,是否有任何免费的数据库呢?如果可以提供链接,我会很高兴。

谢谢。

I'm trying to develop a website where users upload their images as part of registration. I want it that for each image, there should be a thumb created with PHP (which is not that difficult). I want to save the thumbs (since they are very small) in the database and I use MySQL. (I don't want to save the thumbs as physical files on the drive.)
Does MySQL allow saving and retrieving image data and how do I go about it? If it doesn't support image data, is there any free database that does? I will be happy if a link can be provided.
Thanks.

推荐答案

是的,你可以存储数据库中的图像,但在我看来并不可取,这不是一般的做法。

Yes, you can store images in the database, but it's not advisable in my opinion, and it's not general practice.

一般做法是将图像存储在文件系统的目录中,并存储对数据库中图像的引用。例如图像的路径,图像名称等。或者,您甚至可以将图像存储在内容传送网络(CDN)或跨越一大片物理区域的众多主机上,并存储引用以访问数据库中的这些资源。

A general practice is to store images in directories on the file system and store references to the images in the database. e.g. path to the image,the image name, etc.. Or alternatively, you may even store images on a content delivery network (CDN) or numerous hosts across some great expanse of physical territory, and store references to access those resources in the database.

图像可能会变得非常大,大于1MB。因此,将数据存储在数据库中可能会对数据库和数据库与Web服务器之间的网络造成不必要的负担,如果它们位于不同的主机上。

Images can get quite large, greater than 1MB. And so storing images in a database can potentially put unnecessary load on your database and the network between your database and your web server if they're on different hosts.

我曾在拥有400,000多名员工的初创公司,中型公司和大型科技公司工作过。在我13年的专业经验中,我从未见过有人将图像存储在数据库中。我这样说是为了支持这种说法,这是一种不寻常的做法。

I've worked at startups, mid-size companies and large technology companies with 400K+ employees. In my 13 years of professional experience, I've never seen anyone store images in a database. I say this to support the statement it is an uncommon practice.

这篇关于我可以在MySQL中存储图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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