Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert BLOB and CLOB files in MySQL?

Tags:

mysql

ubuntu

qt4

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.

I am using Kubuntu 11.04, MySQL5, Qt 4.7.3.

like image 938
user1411472 Avatar asked May 24 '12 00:05

user1411472


1 Answers

Two ways:

1 - Use a LOAD_FILE function -

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

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

INSERT INTO table1 VALUES    (1, x'89504E470D0A1A0A0000000D494844520000001000000010080200000090916836000000017352474200AECE1CE90000000467414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8640000001E49444154384F6350DAE843126220493550F1A80662426C349406472801006AC91F1040F796BD0000000049454E44AE426082'); 
like image 118
Devart Avatar answered Sep 25 '22 18:09

Devart