As you know from previous article, standard query used to export mysql database to an excel csv file has no column header inside.
To put column header in your exported csv file you can simply modify your query as follow:
SET @sql_text =
INTO OUTFILE ‘C:/myfile.csv’
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
PREPARE s1 FROM @sql_text;
DROP PREPARE s1;
It works!, right?…
Did You notice above code?, to add column header in exported csv file you can combine standard query with UNION ALL function and bundle it as a variable named sql_text.
*) Third line is used to declare the header column name, edit it as you wish.