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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4243610/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:03:05  来源:igfitidea点击:

How to Export SQL Query to TXT Using Command Line

mysqllinuxcommand-lineterminalcommand-line-interface

提问by X10nD

I want to export select * from tableresults to a text file from the command line in linux. How should I do this?

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

Thanks, Jean

谢谢,让

采纳答案by Haim Evgi

look at link

链接

you only need to add this to the query

您只需要将此添加到查询中

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

you can improve this to csv file (using it in excel latter)

您可以将其改进为 csv 文件(后者在 excel 中使用)

like :

喜欢 :

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