MySQL 如何使用 INTO OUTFILE 附加到文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9721175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL how do you append to a file with INTO OUTFILE?
提问by stackoverflow
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
期望的结果是不断地附加到 Results.csv
回答by Gokulnath
You can merge results and write at once. TEE will log everything which might not be desirable. In your case:
您可以合并结果并立即写入。TEE 将记录可能不理想的所有内容。在你的情况下:
SELECT * FROM Results UNION
SELECT * FROM Results INTO OUTFILE '~/TestInput/Results.csv';
回答by Ike Walker
You can't do that with SELECT INTO OUTFILE
. That command only creates new files, and will fail if the file already exists.
你不能用SELECT INTO OUTFILE
. 该命令仅创建新文件,如果文件已存在,则会失败。
You can append query output to an existing files using the TEE
command in the MySQL client.
您可以使用TEE
MySQL 客户端中的命令将查询输出附加到现有文件。
Here's your example appending two query results to the same file using TEE
:
这是您使用以下命令将两个查询结果附加到同一个文件的示例TEE
:
TEE ~/TestInput/Results.csv
SELECT *
FROM Results;
SELECT *
FROM Results;
NOTEE
回答by Devart
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).
无法直接在 MySQL 中执行此操作。但是您可以尝试将日期时间部分添加到文件名中,然后使用“cat”(UNIX 命令)或“type”(DOS 命令)将一些文件组合成一个新文件。
Help: cat (Unix)
帮助:cat (Unix)