简体   繁体   English

mysql over ssh over 非标准端口

[英]mysql over ssh over non-standard port

I am on computer A, and have mysql running on it, and can connect to it as A~ $ mysql -u punkish -p database and so on.我在电脑A上,运行着mysql,可以连接到A~ $ mysql -u punkish -p database等等。

I have access to computer B that also has mysql running on it.我可以访问也运行 mysql 的计算机 B。 I can ssh into B over port 2200 with ssh key pairs set up, and once in, I can connect to the db like so我可以 ssh 通过端口 2200 进入 B 并设置 ssh 密钥对,一旦进入,我可以像这样连接到数据库

A~ $ ssh -p 2200 punkish@B
B~ $ mysql -u punkish -p database

However, I want to set up port forwarding over ssh on my computer so all requests made for mysql on port 3307 on my computer A are actually sent to port 3306 on B. This will allow me to use a gui program that wants to connect to mysql, but can't do it over a tunnel.但是,我想在我的计算机上通过 ssh 设置端口转发,因此在我的计算机 A 上的端口 3307 上对 mysql 发出的所有请求实际上都发送到 B 上的端口 3306。这将允许我使用想要连接到的 gui 程序mysql,但不能通过隧道进行。 So, I do the following所以,我做以下

A~ $ ssh -p 2200 -L 3307:B:3306 punkish@B
B~ $

The above logs me right into B. I am not sure if the tunnel is established, but I am assuming it is.以上将我直接登录到 B。我不确定隧道是否已建立,但我假设它是。 However, the following fails (in another terminal但是,以下失败(在另一个终端

A~ $ mysql -P 3307 -u punkish -p
Enter password:
ERROR 1045 (28000): Access denied for user 'punkish'@'localhost' (using password: YES)

Here is the interesting thing -- I have another gui program called Sequel Pro (a desktop MySQL client for Mac OS X), and that is able to make a connection to mysql@B over ssh just fine.这是有趣的事情——我有另一个名为 Sequel Pro 的 gui 程序(Mac OS X 的桌面 MySQL 客户端),它能够通过 ssh 连接到 mysql@B 就好了。 So, I know something works... I just don't know how, so I may be able to enable it for another gui program.所以,我知道有些东西有效......我只是不知道如何,所以我可以为另一个 gui 程序启用它。

mysql usually attempts to use a socket file if you don't specify a hostname.如果您不指定主机名,mysql 通常会尝试使用套接字文件。 So as part of your mysql command, specify -h 127.0.0.1 (notice I did NOT say localhost, it treats them differently).因此,作为 mysql 命令的一部分,指定-h 127.0.0.1 (注意我没有说 localhost,它对待它们的方式不同)。 This basically forces a TCP connection instead of the socket file connection.这基本上强制 TCP 连接而不是套接字文件连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM