我可以通过 Sequel Pro 连接到数据库,但不能通过命令行
我可以使用 Sequel Pro 连接到我的数据库,但无法通过命令行。我已按照他们的说明进行操作: http://www.sequelpro.com/docs/Connecting_to_a_MySQL_Server_on_a_Remote_Host#Do_I_need_to_use_the_Terminal_for_SSH_connections.3F
我从 Sequel Pro 的连接窗口和 SSH 选项卡中替换了以下内容:
ssh -L 1234:mysqlhost:3306 sshuser@sshhost
mysqlhost => MySQL Host
sshuser => SSH User
sshhost => SSH Host
在他们的命令中, 密码,我使用“SSH 密码”中的密码,
我不确定 Sequel Pro 正在做什么幕后不一样。
I can connect to my db with Sequel Pro just fine, but I can't through the command line. I've followed their instructions here: http://www.sequelpro.com/docs/Connecting_to_a_MySQL_Server_on_a_Remote_Host#Do_I_need_to_use_the_Terminal_for_SSH_connections.3F
In their command I substitute the following from the connection window and SSH tab in Sequel Pro:
ssh -L 1234:mysqlhost:3306 sshuser@sshhost
mysqlhost => MySQL Host
sshuser => SSH User
sshhost => SSH Host
And when prompted for a password, I use the one from "SSH Password"
I'm not sure what Sequel Pro is doing differently behind the scenes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Sequel Pro 文档中的说明并不完全是故事的全部;它只是告诉您如何建立隧道。您需要第二步才能实际使用它来连接到 MySQL 服务器。
实际过程分为两个步骤:
创建隧道。
<前><代码>ssh -N -L 1234:mysqlhost:3306 sshuser@sshhost
我添加的
-N
只是告诉ssh
您只是设置隧道,并且不想启动sshhost
上的 shell。运行此命令看起来就像什么都不做:这就是它应该看起来的样子。只要
ssh
命令正在运行,到本地计算机上端口 1234 的连接就会通过sshhost
隧道连接到上的端口 3306(MySQL 端口) >mysqlhost
.使用隧道连接到 MySQL。
您现在需要运行
mysql
命令行客户端。您刚刚运行的 ssh 命令仍在运行,因此您要做的最简单的事情就是打开一个新的终端窗口或选项卡,然后运行:<前><代码>mysql -P 1234 -u mysqluser -p
连接到您的数据库。
-P 1234
部分是该命令中唯一不寻常的部分,它只是使mysql
客户端使用您在命令中设置的端口进行连接。第一个执行隧道的命令。完成隧道后,关闭原始终端窗口或使用 Ctrl-C 停止
ssh
进程。That instruction from the Sequel Pro docs isn't quite the whole story; it's just telling you how to set up a tunnel. You need a second step to actually use it to connect to a MySQL server.
The actual process is two steps:
Create the tunnel.
The
-N
that I added just tellsssh
that you're only setting up a tunnel and you don't want to start a shell onsshhost
. Running this command will look like it does nothing: that's what it should look like.As long as the
ssh
command is running, connections to port 1234 on your local machine will be tunneled throughsshhost
to port 3306 (the MySQL port) onmysqlhost
.Connect to MySQL using the tunnel.
You now need to run the
mysql
command line client. Thessh
command you just ran is still running, so the easiest thing for you to do is open a new Terminal window or tab, and run:to connect to your database. The
-P 1234
part is the only out-of-the-ordinary part of this command, and it just makes themysql
client connect using the port you set up in the first command to do the tunneling.When you're done with the tunnel, either close the original Terminal window or use Ctrl-C to stop the
ssh
process.