如何使用命令行将SQL查询导出到TXT

时间:2010-11-22 08:33:30

标签: mysql linux command-line terminal command-line-interface

我想将select * from table结果导出到linux中命令行的文本文件中。我该怎么做?

谢谢, 让

1 个答案:

答案 0 :(得分:17)

查看link

您只需将其添加到查询

select * from table INTO OUTFILE '/tmp/myfilename.txt'

你可以将它改进为csv文件(在excel后面使用它)

喜欢:

INTO OUTFILE '/tmp/myfilename.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'