通过 ssh 建立连接 [英] Sequelize connection over ssh

查看:91
本文介绍了通过 ssh 建立连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 sequelize 连接到远程 mysql 服务器,但我能够通过 ssh 连接到机器并连接到 mysql.

I am not able to connect to a remote mysql server using sequelize but I am able to ssh into the machine and connect to mysql.

如何让 Sequelize 通过 ssh 而不是直接在节点中连接到 mysql 服务器?

How do I make Sequelize connect to mysql server over ssh rather than directly in node?

推荐答案

您设置了到服务器的 SSH 隧道,该隧道侦听(例如)端口 33060:

You set up an SSH tunnel to your server, which listens on (for example) port 33060:

ssh -NL 33060:localhost:3306 yourserver

在另一个窗口/终端中,您可以使用 MySQL 客户端(假设它安装在本地)通过 SSH 隧道连接到远程 MySQL 服务器:

In another window/terminal, you can use the MySQL client (assuming that it's installed locally) to connect to the remote MySQL server over the SSH tunnel:

mysql --port 33060 --host 127.0.0.1

如果可行,只需更改 Sequelize 中的端口号即可:

If that works, it's just a matter of changing the port number in Sequelize:

var sequelize = new Sequelize('database', 'username', 'password', {
  host: "127.0.0.1",
  port: 33060
});

如果它不起作用,则可能是远程 MySQL 服务器未配置为接受 TCP 连接.如果是这种情况,您应该配置您的 MySQL 服务器以获取它 接受 TCP 连接.

If it doesn't work, it might be that the remote MySQL server isn't configured to accept connections over TCP. If that's the case, you should configure your MySQL server to get it to accept TCP connections.

这篇关于通过 ssh 建立连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆