Bug #109143 INTO OUTFILE - Add include columns option
Submitted: 18 Nov 2022 19:44 Modified: 22 Nov 2022 7:06
Reporter: Mark Athas Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S4 (Feature request)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[18 Nov 2022 19:44] Mark Athas
Description:
INTO OUTFILE is great option for some use cases.  Specifically when I use mysql for preliminary data wrangling in data science.  Once data is ready, exporting to a csv is most practical for repeated exploratory data analysis.  Once secure-file-priv= is set, this feature needs 2 options.  The ability to include column headers as row 1.  And the ability to replace a file if it already exists.  (See Suggested Fix)

How to repeat:
New feature request.  The "bug" is having to work around these limitations of the INTO OUTFILE

Suggested fix:
Add two options to the INTO OUTFILE query extension

1) INTO OUTFILE WITH HEADERS

   To include the column headings as row 1 of the file

2) INTO OUTFILE CREATE OR REPLACE

   To allow the file be overwritten if it already exists.

Here's a complete example...

SELECT * 
FROM extendedchange
ORDER BY date_time DESC
INTO OUTFILE WITH HEADERS CREATE OR REPLACE '/Users/me/Documents/Dumps/extendedchange.csv';
[22 Nov 2022 7:05] MySQL Verification Team
Thank you for the feature request.