在 MySQL 中使用什么数据类型来存储图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2475065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What data type to use in MySQL to store images?
提问by rajson
I need to store image and resume of user in the data base.
我需要在数据库中存储用户的图像和简历。
I am using mysql data base and php5. I need to know which data types I should use.
我正在使用 mysql 数据库和 php5。我需要知道我应该使用哪些数据类型。
And also how do I set a limit (maximum size) for uploaded data.
以及如何为上传的数据设置限制(最大大小)。
回答by lexu
回答by Nidhin David
Perfect answer for your question can be found on MYSQL site itself.refer their manual(without using PHP)
您的问题的完美答案可以在 MYSQL 站点上找到。参考他们的手册(不使用 PHP)
http://forums.mysql.com/read.php?20,17671,27914
http://forums.mysql.com/read.php?20,17671,27914
According to them use LONGBLOBdatatype. with that you can only store images less than 1MB only by default,although it can be changed by editing server config file.i would also recommend using MySQL workBench for ease of database management
根据他们使用LONGBLOB数据类型。默认情况下,您只能存储小于 1MB 的图像,尽管可以通过编辑服务器配置文件进行更改。我还建议使用 MySQL workBench 以方便数据库管理
回答by FONGOH MARTIN
This can be done from the command line. This will create a column for your image with a NOT NULL
property.
这可以从命令行完成。这将为您的图像创建一个具有NOT NULL
属性的列。
CREATE TABLE `test`.`pic` (
`idpic` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`caption` VARCHAR(45) NOT NULL,
`img` LONGBLOB NOT NULL,
PRIMARY KEY(`idpic`)
)
TYPE = InnoDB;
From here
从这里