如何从本地计算机上mysqldump远程数据库 [英] how to mysqldump remote db from local machine
问题描述
我需要在远程服务器上执行数据库的mysqldump,但该服务器未安装mysqldump.我想使用机器上的mysqldump连接到远程数据库并在机器上进行转储.
I need to do a mysqldump of a database on a remote server, but the server does not have mysqldump installed. I would like to use the mysqldump on my machine to connect to the remote database and do the dump on my machine.
我试图创建一个ssh隧道,然后进行转储,但这似乎不起作用.我试过了:
I have tried to create an ssh tunnel and then do the dump, but this does not seem to work. I tried:
ssh -f -L3310:remote.server:3306 user@remote.server -N
成功创建隧道.如果我这样做
The tunnel is created with success. If I do
telnet localhost 3310
我得到一些显示正确服务器mysql版本的内容.但是,执行以下操作似乎尝试在本地连接
I get some blurb which shows the correct server mysql version. However, doing the following seems to try to connect locally
mysqldump -P 3310 -h localhost -u mysql_user -p database_name table_name
推荐答案
正如我在serverfault上尚未看到的那样,答案很简单:
As I haven't seen it at serverfault yet, and the answer is quite simple:
更改:
ssh -f -L3310:remote.server:3306 user@remote.server -N
收件人:
ssh -f -L3310:localhost:3306 user@remote.server -N
然后更改:
mysqldump -P 3310 -h localhost -u mysql_user -p database_name table_name
收件人:
mysqldump -P 3310 -h 127.0.0.1 -u mysql_user -p database_name table_name
(不要使用localhost,这是可能是通过套接字而不是通过端口连接的这些特殊含义"废话之一)
(do not use localhost, it's one of these 'special meaning' nonsense that probably connects by socket rather then by port)
编辑:好,要详细说明:如果将主机设置为localhost
,则假定已配置(或默认)--socket
选项.请参阅手册,其中将查找/使用选项文件.在Windows下,这可以是命名管道.
edit: well, to elaborate: if host is set to localhost
, a configured (or default) --socket
option is assumed. See the manual for which option files are sought / used. Under Windows, this can be a named pipe.
这篇关于如何从本地计算机上mysqldump远程数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!