# mysql用SQL语句存储图片

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';
• 0
点赞
• 2
评论
• 3
收藏
• 一键三连
• 扫一扫，分享海报

12-27 245

10-11 3258
05-28 1万+
03-29 887
12-09 469
02-02 11万+
08-03 1万+
06-16 995
09-14 7368