I need to execute a query multiple times with different variables and redirect the output into an output file defined in a variable.
I am trying something like
SET @OUTFILE = '/tmp/outfile_1';
select *
from db
INTO OUTFILE @OUTFILE;
but I have the error
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@OUTFILE'
Any idea how to resolve this issue?