本文介绍了何时将图像存储在数据库(mySQL)中以及何时不存在? (将图像链接到数据库中的项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这不是这里要问的问题的类型,但我通读了FAQ,它看起来应该没问题。



背景信息:作为毕业项目的一部分,我的小组正在为将要显示菜单的餐厅创建一个网站。当用户鼠标悬停的项目名称时,菜单将具有鼠标悬停功能以显示食物图像。我最初的计划是不将菜单信息存储在数据库中,因为它不会经常更改。有两个不同的位置,菜单项不同。因此,对我来说,将所有信息存储在数据库中并仅使用HTML显示它似乎是一种浪费。我们的教授对15年前使用的技术并不十分了解,告诉我们他知道将这些信息存储在数据库中会更好。对我来说,这似乎会让事情变得很混乱,没有附加价值。另外最初我打算将鼠标悬停的图像存储在服务器上的简单文件夹中,但是如果所有菜单项都存储在数据库中,我不知道如何将不同图像链接到数据库中的不同项目将图像存储在数据库中。 该网站将主要使用html,php,mysql和一些javascript 我们也将开发一个android应用程序,以基本模仿网站上的内容,如果这样做会改变某些事情。



问题 - 这是否会更好地存储在数据库中,并参考我计划使用它们的方式?如果是这样,有没有办法做到这一点,而不将图像存储在数据库中,并将它们保存在服务器上的文件夹中,反之亦然。



我读过很多在其他论坛上在线解释说你通常不想将图像存储在数据库中,但由于我的教授认为他说的正确,菜单必须存储在数据库中,所以我假设我必须将图像存储在数据库中以及所以鼠标悬停功能将正常工作。如果这甚至是可能的,我只使用鼠标悬停功能与服务器上的映像位置,而不是引用数据库。感谢您的帮助和见解。

解决方案




  • 存储图像自动成为交易的一部分

  • 无需清理文件系统并将其与数据库同步

  • 访问图像是通过访问其余数据的相同方式来控制的。

  • 只有一个备份需要关心

  • 数据库是通常更适合存储百万(如果不是数十亿)记录。在文件系统中,你必须在多个目录上找到一个聪明的分配。单个目录将无法有效处理数百万个文件。对于某些工作负载,将数据存储在数据库中可能实际上更快。

    对于SQL Server,微软已经测试过了:

    如果其他数据库的行为类似,我不会感到惊讶。 / li>


缺点:$ b​​
$ b


  • 使您的数据库和因此你的备份要大得多(考虑恢复它的时间)。

  • 文件系统通常对增量备份更好(除非您拥有Oracle的RMAN)
  • 图像不能被其他应用程序访问(例如,Web服务器,图像大小调整工具,FTP服务器)

  • 图像无法在内容分发网络上传播,以便在Web应用程序中进行负载平衡(从应用程序服务器上卸载)

  • 常见的看法是,从数据库中检索会比较慢。对于某些检索blob的数据库,
  • 实际上可能会降低数据库缓存的效率(并非如此对于Oracle,SQL Server和PostgreSQL,我不知道MySQL)

    Sorry if this is not the type of question to be asked here but I read through the FAQ and it seemed like it should be fine.

    Background info: As apart of a graduating project, my group is creating a site for a restaurant that will have a menu shown. The menu will have mouse-over functions to display an image of the food when the user mouseover's the item name. My original plan was to not store the menu information in a database being that it is not going to change very often. There are two different locations with different menu items. So all in all to me it seemed like it would be a waste to store all that info in a database and just display it using HTML. Our professor who is not very tech savvy beyond what was used 15 years ago, informed us he knows it would be better to store this info in a database. To me this seems like it would really confuse things a lot with no added value. Also originally I planned on storing the images for the mouseover in a simple folder on the server but if all the menu items will be stored in the database I wouldn't know how to link the different images to the different items in the database without also storing the images in the database. The site will mainly use html, php, mysql and some javascript We will also be developing an android application to just basically mimic what is on the website, if that changes things at all.

    The question- Would this be something that would be better to be stored in a database in reference to the way i plan on using them? If so, Is there a way to do this without storing the images in the database and keeping them in a folder on the server or vice versa.

    I have read a lot online in other forums explaining that you typically want to refrain from storing images in a database but since my professor thinks he is right in saying that the menu has to be stored in the database, I assume I would have to store the images in the database as well so the mouseover function will work properly. If this is even possible, I have only used mouseover functions with image locations on a server not from referencing the database. Thanks for all your help and insight.

    解决方案

    Advantages of storing images/blobs in the database

    • Storing the images is automatically part of your transactions
    • No need to cleanup the file system and sync it with the database
    • Access to the images is controlled through the same means as access to the rest of the data
    • Only one single backup to care about
    • A database is usually better suited to stored million (if not billions) of records. In the filesystem you have to find a clever distribution over several directories. A single directory will not be able to handle millions of files efficiently.
    • For some workloads storing the images in the database could actually be faster.
      For SQL Server, Microsoft has actually tested this:
      http://research.microsoft.com/apps/pubs/default.aspx?id=64525
      I wouldn't be surprised if other databases behaved in a similar way.

    Disadvantages:

    • Makes your database and thus your backups a lot bigger (think of the time it takes to restore it).
    • filesystems are usually better with incremental backups (unless you have Oracle's RMAN that is)
    • the images cannot be access by other applications (e.g. a WebServer, image resizing tools, FTP Server)
    • Images can't be spread across a content distribution network for load balancing in a web application (to take load off the application server)
    • common belief is, that the retrieval from the database will be slower.
    • for some databases retrieving the blobs might actually decrease the efficiency of the database cache (not so for Oracle, SQL Server and PostgreSQL. I don't know for MySQL though)

    这篇关于何时将图像存储在数据库(mySQL)中以及何时不存在? (将图像链接到数据库中的项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 02:44