如何在 MySQL 中插入 BLOB 和 CLOB 文件? [英] How to insert BLOB and CLOB files in MySQL?

查看:115
本文介绍了如何在 MySQL 中插入 BLOB 和 CLOB 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我的软件前端存储图像和 .docx/.doc、.pptx/.ppt、.pdf 文件.我不明白如何实现这一点以及如何将 BLOB 和 CLOB 文件插入表中.请帮忙.

I want to store images and .docx/.doc, .pptx/.ppt, .pdf files using the front end of my software. I don't understand how to implement this and how to insert the BLOB and CLOB files into the table. Please help.

我使用的是 Kubuntu 11.04、MySQL5、Qt 4.7.3.

I am using Kubuntu 11.04, MySQL5, Qt 4.7.3.

推荐答案

两种方式:

1 - 使用 LOAD_FILE 函数 ->

1 - Use a LOAD_FILE function -

INSERT INTO table1 VALUES(1, LOAD_FILE('data.png'));

2 - 将文件作为十六进制字符串插入,例如-

2 - Insert file as hex string, e.g. -

INSERT INTO table1 VALUES 
  (1, x'89504E470D0A1A0A0000000D494844520000001000000010080200000090916836000000017352474200AECE1CE90000000467414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8640000001E49444154384F6350DAE843126220493550F1A80662426C349406472801006AC91F1040F796BD0000000049454E44AE426082');

这篇关于如何在 MySQL 中插入 BLOB 和 CLOB 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆