在 Powershell 中使用 MySQL,如何将脚本结果通过管道传输到 csv 文件中?
在 PowerShell 中,如何执行 mysql 脚本以便将结果通过管道传输到 csv 文件中?该脚本的结果只是一小部分列,我想将其复制到 csv 文件中。
我可以通过执行以下操作将其直接转到 shell:
mysql> source myscript.sql
我尝试了各种小事情,例如:
mysql> source myscript.sql > mysql.out
mysql> source myscript.sql > mysql.csv
在无限变化中,但我只是收到错误。我的数据库连接没问题,因为我可以从命令行等执行基本的表查询...到目前为止我也无法在网上找到解决方案...
任何帮助将不胜感激!
In PowerShell, how do I execute my mysql script so that the results are piped into a csv file? The results of this script is just a small set of columns that I would like copied into a csv file.
I can have it go directly to the shell by doing:
mysql> source myscript.sql
And I have tried various little things like:
mysql> source myscript.sql > mysql.out
mysql> source myscript.sql > mysql.csv
in infinite variation, and I just get errors. My db connections is alright because I can do basic table queries from the command line etc... I haven't been able to find a solution on the web so far either...
Any help would be really appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎没有运行 powershell,而是运行 mysql 命令行工具(不过也许您在 powershell 控制台中启动了它。)
另请注意,mysql 命令行工具无法直接导出到 csv。
但是,要将输出重定向到只需运行的文件
或例如
(以及您需要的 mysql 的任何参数,例如用户名、主机名)
You seem to not be running powershell, but the mysql command line tool (perhaps you started it in a powershell console though.)
Note also that the mysql command line tool cannot export directly to csv.
However, to redirect the output to a file just run
or e.g.
(and whatever arguments to mysql you need, like username, hostname)
您在寻找 SELECT INTO OUTFILE 吗? dev.mysql.com/doc/refman/5.1/en/select.html – Pekka 19 小时前
是的。选择到输出文件中工作!但为了确保获得列名称,您还需要执行以下操作:
Are you looking for SELECT INTO OUTFILE ? dev.mysql.com/doc/refman/5.1/en/select.html – Pekka 19 hours ago
Yep. Select into outfile worked! But to make sure you get column names you also need to do something like: