如何在Windows环境下以csv格式输出MySQL查询结果? [英] How to output MySQL query results in csv format in Windows environment?
问题描述
是否有一种简单的方法可以从PowerShell命令行运行MySQL查询并将结果输出到csv格式的文件中?
Is there an easy way to run a MySQL query from the PowerShell command line and output the results into a csv formatted file?
此问题与如何以CSV格式输出MySQL查询结果?(在Windows中除外).我必须在PowerShell中弄清楚,但我的答案不属于linux问题.这是Windows + PowerShell的同级产品.
This question is the same as How to output MySQL query results in CSV format? except in Windows. I had to figure it out in PowerShell but my answer didn't belong on the linux question. So here's the Windows+PowerShell sibling.
推荐答案
Stan's answer from How to output MySQL query results in CSV format?, adapted for Windows PowerShell
mysql my_database_name -u root | Out-File .\my_output_file.csv
这给了我一个mysql提示,但是开始时没有通常的mysql >
.我输入:
This gives me a mysql prompt, but without the usual mysql >
at the start. I type:
source C:\Aboslute\Path\With Spac es\Without\Quotes\To\my_select_statement.sql
如果命令有问题,它会给出一条错误消息并退出,或者如果命令成功执行,则会提示我为空.我键入exit
完成.
It gives an error message and exits if there is a problem with the command, or gives me the empty prompt if the command executed successfully. I type exit
to finish up.
这篇关于如何在Windows环境下以csv格式输出MySQL查询结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!