将sql查询的结果写入mysql中的文件 [英] write results of sql query to a file in mysql

查看:161
本文介绍了将sql查询的结果写入mysql中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用mysql将查询结果写入文件.我已经在几个地方看到了关于outfile构造的一些信息,但是似乎这只会将文件写入运行MySQL的机器(在这种情况下,这是一个远程机器,即数据库不在我的本地机器上).

I'm trying to write the results of a query to a file using mysql. I've seen some information on the outfile construct in a few places but it seems that this only writes the file to the machine that MySQL is running on (in this case a remote machine, i.e. the database is not on my local machine).

或者,我也尝试过运行查询并从mysql工作台结果窗口中获取(复制/粘贴)结果.这适用于一些较小的数据集,但最大的数据集似乎太大,会导致内存不足异常/错误/崩溃.

Alternatively, I've also tried to run the query and grab (copy/paste) the results from the mysql workbench results window. This worked for some of the smaller datasets, but the largest of the datasets seems to be too big and causing an out of memory exception/bug/crash.

在此问题上的任何帮助将不胜感激.

Any help on this matter would be greatly appreciated.

推荐答案

您可以尝试从本地cli执行查询,然后将输出重定向到本地文件目的地;

You could try executing the query from the your local cli and redirect the output to a local file destination;

mysql -user -pass -e"select cols from table where cols not null" > /tmp/output

这篇关于将sql查询的结果写入mysql中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆