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

查看:23
本文介绍了我可以在 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.

我曾在拥有 40 万多名员工的初创公司、中型公司和大型科技公司工作过.在我 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天全站免登陆