How to insert BLOB and CLOB files in MySQL?

前端 未结 6 974
猫巷女王i
猫巷女王i 2020-11-28 08:26

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 CL

6条回答
  •  Happy的楠姐
    2020-11-28 08:53

    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');
    

提交回复
热议问题