mysqlblob

How to write an image blob to a disk?


I have a table that contains image BLOB field.

I want to be able to submit a query to the database and have the BLOBs written to the Windows file system.

Is this possible?


Solution

  • Yes, it is possible. You can use SELECT command with INTO DUMPFILE clause. For example -

    SELECT
      data_column
    FROM
      table1
    WHERE
      id = 1
    INTO DUMPFILE 'image.png';
    

    From the reference: If you use INTO DUMPFILE instead of INTO OUTFILE, MySQL writes only one row into the file, without any column or line termination and without performing any escape processing. This is useful if you want to store a BLOB value in a file.