Include headers when using SELECT INTO OUTFILE?

Brett picture Brett · May 9, 2011 · Viewed 177.8k times · Source

Is it possible to include the headers somehow when using the MySQL INTO OUTFILE?

Answer

Joe Stefanelli picture Joe Stefanelli · May 9, 2011

You'd have to hard code those headers yourself. Something like:

SELECT 'ColName1', 'ColName2', 'ColName3'
UNION ALL
SELECT ColName1, ColName2, ColName3
    FROM YourTable
    INTO OUTFILE '/path/outfile'