我可以通过 Sequel Pro 连接到数据库,但不能通过命令行

发布于 2025-01-02 03:11:57 字数 605 浏览 1 评论 0原文

我可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

波浪屿的海角声 2025-01-09 03:11:57

Sequel Pro 文档中的说明并不完全是故事的全部;它只是告诉您如何建立隧道。您需要第二步才能实际使用它来连接到 MySQL 服务器。

实际过程分为两个步骤:

  1. 创建隧道。

    <前><代码>ssh -N -L 1234:mysqlhost:3306 sshuser@sshhost

    我添加的 -N 只是告诉 ssh只是设置隧道,并且不想启动sshhost 上的 shell。运行此命令看起来就像什么都不做:这就是它应该看起来的样子。

    只要 ssh 命令正在运行,到本地计算机上端口 1234 的连接就会通过 sshhost 隧道连接到 上的端口 3306(MySQL 端口) >mysqlhost.

  2. 使用隧道连接到 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:

  1. Create the tunnel.

    ssh -N -L 1234:mysqlhost:3306 sshuser@sshhost
    

    The -N that I added just tells ssh that you're only setting up a tunnel and you don't want to start a shell on sshhost. 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 through sshhost to port 3306 (the MySQL port) on mysqlhost.

  2. Connect to MySQL using the tunnel.

    You now need to run the mysql command line client. The ssh 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:

    mysql -P 1234 -u mysqluser -p
    

    to connect to your database. The -P 1234 part is the only out-of-the-ordinary part of this command, and it just makes the mysql 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文