使用LOAD_FILE()函数在MySQL数据库中插入BLOB字段的正确方法
作者:互联网
SELECT LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/pic/11.jpg') AS RESULT;
2.检查文件大小是否小于允许的最大字节。
show variables like 'max_allowed_packet';
说明允许文件最大为64MB。
3.查看允许上传文件的目录。
show variables like 'secure_file_priv';
说明:ProgramData文件夹是隐藏的。只有将文件放置到上述目录中才能成功读取到。
3‘.参考:https://blog.csdn.net/s0cket/article/details/114109084
4.实例。《Qt6开发及实例》(第5版)郑阿奇主编,13.4Qt操作流行关系数据库及实例,在commodity数据表中插入六条记录并创建视图,如下:
/***************************添加记录、创建数据视图********************************/
INSERT INTO commodity VALUES(1,'CORTUBO潜水拉链长袖防晒分体泳衣',LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/pic/11.jpg'),255.60,357.84,478);
INSERT INTO commodity VALUES(2,'空姐制服2022时尚气质女工作服',LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/pic/12.jpg'),158,306,398644);
INSERT INTO commodity VALUES(3,'职业套装女2022新款OL面试正装',LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/pic/13.jpg'),688,788.98,12416);
INSERT INTO commodity VALUES(4,'HUAWEI/华为mate 30手机',LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/pic/31.jpg'),3388,3888,1235);
INSERT INTO commodity VALUES(5,'延禧攻略网红传统糕点饼干礼盒',LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/pic/22.jpg'),158,188,796);
INSERT INTO commodity VALUES(6,'【三只松鼠】小吃货抖音美食大礼包',LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/pic/21.jpg'),59.90,130.00,138081);
CREATE VIEW commodity_inf AS SELECT Name AS '商品名称',InputPrice AS '进价(¥)',OutputPrice AS '售价(¥)',Amount AS '库存' FROM commodity;
说明:操作MySQL数据库工具,我使用的是“Navicat Premium 15”。Qt本版是Qt6.3.1。
5.Qt6.3.1使用MySQL数据库的驱动网址链接:https://www.cnblogs.com/managechina/p/16456912.html。
标签:LOAD,commodity,ProgramData,Server,BLOB,FILE,MySQL 来源: https://www.cnblogs.com/zdt168/p/16584900.html