问题
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
回答1:
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';
回答2:
You can't do that with SELECT INTO OUTFILE
. That command only creates new files, and will fail if the file already exists.
You can append query output to an existing files using the TEE
command in the MySQL client.
Here's your example appending two query results to the same file using TEE
:
TEE ~/TestInput/Results.csv
SELECT *
FROM Results;
SELECT *
FROM Results;
NOTEE
回答3:
It is not possible to do it directly in MySQL. But you may try to add date-time part into file name, then combine some files to a new one with a 'cat' (UNIX command) or 'type' (DOS command).
Help: cat (Unix)
来源:https://stackoverflow.com/questions/9721175/mysql-how-do-you-append-to-a-file-with-into-outfile