mysql从远程数据库转储到localhost outfile [英] mysql dump to localhost outfile from a remote database

查看:250
本文介绍了mysql从远程数据库转储到localhost outfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困住了.我基本上想使用OUTFILE命令从远程数据库创建本地数据文件(csv文件).

I'm stuck. I basically want to create a LOCAL data file (csv file) from a remote database using the OUTFILE command.

我基本上是在提取数据..并想在我的本地文件服务器上创建它,而不是在远程服务器上创建outfile.我在远程空间上受到限制,因此我想在本地创建文件.我该怎么做呢?谢谢!

I am basically, pulling data.. and want to create it on my local file server vs. creating the outfile on the remote server. I'm limited on space remotely, thus I want to create the file locally. What am I missing on how to do this? Thanks!

到目前为止,这是我在命令行上的工作语法(它正在创建我想要的文件,但在远程服务器上)

This is my working syntax so far on the command line (it is creating the file I want, but on the remote server)

mysql -u test -pfoo --database test -h testdb201.name.host.com --port 3306 -ss -e "SELECT 'a','b','c' UNION SELECT col1, col2, col3 INTO OUTFILE '/tmp/mytest.csv' FIELDS TERMINATED BY ','  FROM tst_p000 limit 10"

推荐答案

根据

According to the MySQL Select syntax, You can't use OUTFILE to output to a file outside the server itself.

您需要将查询的制表符分隔输出转换为CSV格式,例如(

You would need to converted the tab-delimited output of the query to CSV format like this (sed command credited here).

mysql -u test -pfoo --database test -h testdb201.name.host.com --port 3306 -ss -e "SELECT 'a','b','c' UNION SELECT col1, col2, col3 " | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > myDump.csv

这篇关于mysql从远程数据库转储到localhost outfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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