If the image is located on your MySQL host, you could use the LOAD_FILE() command for storing an image in a BLOB:
-- Using the following table as an example:
CREATE TABLE MyTable (
image BLOB
);
-- This will insert a file in a BLOB column.
INSERT INTO MyTable (image) VALUES(LOAD_FILE('/tmp/image.png'));
该文件路径为'd:/tmp/image1.png'
Make sure that the image file is readable by MySQL, and also make sure that your MySQL user has the FILE privilege.
To grant the FILE privilege, log-in as root and execute:
GRANT FILE ON *.* TO 'mysql_user'@'localhost';
本文介绍如何使用MySQL的LOAD_FILE()命令将图片文件存储到BLOB字段中,并确保MySQL用户具备FILE权限的方法。

722

被折叠的 条评论
为什么被折叠?



