[mysql] Include headers when using SELECT INTO OUTFILE?

Since the 'include-headers' functionality doesn't seem to be build-in yet, and most "solutions" here need to type the columns names manually, and/or don't even take joins into account, I'd recommand to get around the problem.

  • The best alternative I found so far is using a decent tool (I use HeidiSQL).
    Put your request, select the grid, just right click and export to a file. It got all necessary options for a clean export, ans should handle most needs.

  • In the same idea, user3037511's approach works fine, and can be automated easily.
    Just launch your request with some command line to get your headers. You may get the data with a SELECT INTO OUTFILE... or by running your query without the limit, yours to choose.

    Note that output redirect to a file works like a charm on both Linux AND Windows.


This makes me want to highlight that 80% of the time, when I want to use SELECT FROM INFILE or SELECT INTO OUTFILE, I end-up using something else due to some limitations (here, the absence of a 'headers options', on an AWS-RDS, the missing rights, and so on.)

Hence, I don't exactly answer to the op's question... but it should answer his needs :)
EDIT : and to actually answer his question : no
As of 2017-09-07, you just can't include headers if you stick with the SELECT INTO OUTFILE command
:|