通过SSH隧道的MySQL连接-如何指定其他MySQL服务器? [英] MySQL connection over SSH tunnel - how to specify other MySQL server?
问题描述
我已经建立了约50个数据库,它们都使用不同的主机名设置,要求我通过SSH隧道连接到它们.
I've got ~50 databases all set up at different host names, with the requirement that I connect to them through an SSH tunnel.
例如:
-
ssh.example.com
位于mysql1.example.com
我已经设法使用autossh(运行Debian的Web服务器)创建隧道,但似乎无法弄清楚如何连接到SSH隧道之外的特定MySQL主机名.
I have managed to create the tunnel using autossh (web server running Debian), but I can't seem to figure out how to connect to a specific MySQL hostname "beyond" the SSH tunnel.
键入lsof -i -n | egrep '\<ssh\>'
确认隧道正在运行(将端口3307发送到ssh.example.com端口3306)
Typing lsof -i -n | egrep '\<ssh\>'
confirms that the tunnel is working (sends port 3307 to ssh.example.com port 3306)
因此,当我尝试mysql -h 127.0.0.1 -P 3307
时,我得到连接被拒绝.不太奇怪,因为它不是MySQL服务器.
So when I try mysql -h 127.0.0.1 -P 3307
I get Connection refused. Not too weird since it's not an MySQL server.
我对你们的问题:
在创建SSH隧道后如何指定mysql1.example.com
主机?我尝试过在所有地方搜索,但似乎无法弄清楚.
How do I specify the mysql1.example.com
host AFTER creating the SSH tunnel? I've tried searching everywhere but can't seem to figure it out.
推荐答案
解决了!事情是在创建隧道本身时连接到正确的服务器-应该已经看到一台即将到来的服务器.
Solved it! The thing was to connect to the correct server when creating the tunnel itself - should've seen that one coming.
ssh -f user@ssh.example.com -L 3307:mysql1.example.com:3306 -N
然后mysql -h 127.0.0.1 -P 3307
正常工作. :)
这篇关于通过SSH隧道的MySQL连接-如何指定其他MySQL服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!