是否可以在 SQL 数据库中存储图片、声音、视频?
是否可以在 SQL 数据库(或任何其他数据库)中存储图片、声音、视频?如果是,它应该是什么格式,如果有的话,请指定必须配置的特殊设置.提前致谢.
Is it possible to store pictures,sounds,videos in SQL Database (or any other database) ? If yes what format should it be and please specifiy about the special settings that has to be configured if any. Thanks in advance.
推荐答案
在 MySQL 中,您可以使用 BINARY 或 VARBINARY 数据类型将任何二进制内容存储在表中.相当所有的数据库系统都是这样的数据类型.它可用于存储完整的文件内容,例如图片、视频、声音……或只是一个二进制片段.
In MySQL you can store any binary content in a table using the BINARY or VARBINARY data type for a column. Quite all database system as such a data type. It can be used to store a full file content such as picture, video, sound,... or just a binary snippet.
尽管如此,将二进制文件存储在数据库中被认为是一种不好的做法,因为它总是会让人失望.事实上,存储在数据库中的文件无法轻松处理以进行下载、包含在 HTML 页面中、流式传输等.由于它的长度,操作起来总是很复杂.大多数情况下,与存储在目录中的文件相比,在数据库中排序的文件是不利的.建议将文件名存储在数据库中,并将实际文件保存在物理目录中.
Nevertheless, storing binary files in a database is considered as a bad practice, because it quite always brings to disappointments. Indeed, a file stored in database cannot be easily processed for a download, an inclusion in a HTML page, a streaming, ... . And it is quite always complicated to manipulate because of its length. Most often, a file sorted in a database is disadvantageous compared to a file stored in a directory. Its is advised to store the file name in the database base, and save the actual file in a physical directory.
相关文章