mysql - 在 Windows 上通过 putty 编写 ssh 脚本

标签 mysql ssh putty

我需要编写从 Windows 机器恢复 Linux 机器的 mysql 脚本。我有 putty,我知道它具有 ssh 功能。这是我所拥有的:

C:\Progra~1\Putty\putty.exe -ssh root@10.1.2.3 && mysql -u USER -pPASS db < /tmp/dump.sql

我在编写脚本时遇到的问题是 putty 打开一个新窗口并将控制权转移到那里,所以之后会发生任何事情

putty.exe -ssh 

什么都不做。

最佳答案

您可以使用 -m 选项指定一个文件,其中包含要在远程连接上运行的命令。

例子:

C:\Progra~1\Putty\putty.exe -ssh -m C:\cmd.txt root@10.1.2.3

C:\cmd.txt 的内容

 mysql -u USER -pPASS db < /tmp/dump.sql

来自Putty Documentation :

3.8.3.6 `-m': read a remote command or script from a file

The -m' option performs a similar function to theRemote command' box in the SSH panel of the PuTTY configuration box (see section 4.18.1). However, the `-m' option expects to be given a local file name, and it will read a command from that file.

With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain `embedded' servers, such as Cisco routers.

This option is not available in the file transfer tools PSCP and PSFTP.

关于mysql - 在 Windows 上通过 putty 编写 ssh 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12736683/

相关文章:

c# - 使用多条语句执行sql文件

使用公钥 ssh 登录仍然询问密码

macos - 通过 SSH 到 VM 使用 Sublime Text 打开文件,错误

c - AVR C串行通信: Print number Fixed Buttons

ssh - 使用Plink执行远程命令后获取 “Server unexpectedly closed network connection”

ssh - 无法使用 Putty 通过 ssh 启动 X11

php - 如何在mysql中存储顺序数据

mysql - 为什么我的 mysql DB 可以在 Rails 4 中读取而不更新或插入数据?

mysql - 查看由factory_girl在mysql数据库中创建的数据库条目

python - Fabric python 框架中的多主机、多凭据