Sequelize connection over ssh

旧时模样 提交于 2021-01-20 20:10:06

问题


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.

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


回答1:


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

ssh -NL 33060:localhost:3306 yourserver

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

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
});

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.



来源:https://stackoverflow.com/questions/19583467/sequelize-connection-over-ssh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!