MySQL how do you append to a file with INTO OUTFILE?

stackoverflow picture stackoverflow · Mar 15, 2012 · Viewed 24.5k times · Source

I have the following code:

SELECT * INTO OUTFILE'~/TestInput/Results.csv'      
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FROM Results;

Desired results are to continually keep on appending to Results.csv

Answer

Gokulnath picture Gokulnath · Nov 27, 2014

You can merge results and write at once. TEE will log everything which might not be desirable. In your case:

SELECT * FROM Results UNION 
SELECT * FROM Results INTO OUTFILE '~/TestInput/Results.csv';