Set the file name in "SELECT ... INTO DUMPFILE" I am trying to write a query to dump a single LONGBLOB data into a file.

SELECT data FROM table WHERE id = 123 
INTO DUMPFILE fileName


which data, fileName, and id are the fields in the table.

SQL syntax error near fileName occurred when I try to run this query in HeidiSQL 10.2.0.

Does anyone know how to fix this error?

The database is MariaDB 5.5.



The following query works fine by the way:

SELECT data FROM table WHERE id = 123 
INTO DUMPFILE 'data.pdf'
Because the fileName value is from the database you don't need to put the single quotes around it.

SELECT data FROM table WHERE id = 123 
INTO DUMPFILE fileName


I'm not sure how filenames with spaces will come out though if you have any. You could always protect against that by using REPLACE on the filename to either remove them or swap them out with a different character before hand.