自动化mysqldump到本地Windows计算机 [英] Automate mysqldump to local Windows computer
问题描述
我正在尝试在Windows上使用plink
创建到Linux计算机的隧道,并使转储文件最终出现在Windows计算机上.看来此答案是可行的,并且是我提出问题的基础.但是尝试一下并查看其他答案,我发现转储文件仍在Linux机器上.在进入生产环境之前,我正在Windows和Ubuntu 14.04的本地环境中进行尝试.在Windows 8.1中:
I'm trying to use plink
on Windows to create a tunnel to a Linux machine and have the dump file end up on the Windows machine. It would appear that this answer would work and is the basis of my question. But trying it out and looking at other answers I find that the dump file is still on the Linux machine. I'm trying this out in my local environment with Windows and Ubuntu 14.04 before moving to production. In Windows 8.1:
plink sam@192.168.0.20 -L 3310:localhost:3306
mysqldump --port=3310 -h localhost -u sam -p --all-databases > outfile.sql
我尝试使用127.0.0.1
交换第二个localhost
,在转储设置的末尾添加-N
,使用dump命令中的一个表,但是尽管有我的隧道,这好像第一个命令是忽略了.其他答案表明将更多命令添加到脚本,以便我可以使用pscp
复制文件.这也意味着要重新连接到该outfile.sql
的废纸..对于在其他服务器上获取其他转储而言,不是理想的选择.如果是这样,为什么还要使用第一个命令?
I've tried swapping localhost
in the second with 127.0.0.1
, adding -N
to the tail of the tunnel setup, using one table in the dump command but despite my tunnel, it's as if the first command is ignored. Other answers indicate to add more commands to the script so that I can use pscp
to copy the file. That also means to re-connect to trash this outfile.sql
. Not ideal for getting other dumps on other servers. If that's the case, why use the first command at all?
我俯瞰什么?在plink
中,第一个输出是打开Linux服务器,我可以在其中运行mysqldump
命令.但是似乎忽略了第一个命令.你觉得呢?
What am I overlooking? In plink
, the output of the first is to open up the Linux server where I can run the mysqldump
command. But there seems to be ignoring the first command. What do you think?
推荐答案
您有几种选择:
-
将数据库远程转储到远程文件,然后将其下载到您的计算机:
Dump the database remotely to a remote file and download it to your machine afterwards:
plink sam@192.168.0.20 "mysqldump -u sam -p --all-databases > outfile.sql"
pscp sam@192.168.0.20:outfile.sql .
重定向>
在引号内,因此您要将远程计算机上的mysqldump
重定向到远程文件.
The redirect >
is inside the quotes, so you are redirecting mysqldump
on the remote machine to the remote file.
这可能是最简单的解决方案.如果您在下载前先压缩转储文件,那将是最快的,尤其是当您通过慢速网络连接时.
This is probably the easiest solution. If you compress the dump before downloading, it would be even the fastest, particularly if you connect over a slow network.
远程执行mysqldump
,但将其输出重定向到本地:
Execute mysqldump
remotely, but redirect its output locally:
plink sam@192.168.0.20 "mysqldump -u sam -p --all-databases" > outfile.sql
请注意,与前一种情况相比,重定向>
在引号之外,因此您正在重定向plink
的输出,即,远程shell的输出,其中包含远程mysqldump
的输出.
Note that the redirect >
is outside of the quotes, comparing to the previous case, so you are redirecting an output of plink
, i.e. output of the remote shell, which contains output of a remote mysqldump
.
隧道连接到远程MySQL数据库,并使用MySQL的本地安装(mysqldump
)在本地转储数据库:
Tunnel connection to the remote MySQL database and dump the database locally using a local installation of MySQL (mysqldump
):
plink sam@192.168.0.20 -L 3310:localhost:3306
在单独的本地控制台(cmd.exe
)中:
In a separate local console (cmd.exe
):
mysqldump --port=3310 -h localhost -u sam -p --all-databases > outfile.sql
在这种情况下,没有任何远程运行(隧道端除外).
In this case nothing is running remotely (except for a tunnel end).
这篇关于自动化mysqldump到本地Windows计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!