Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize connection over ssh

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?

like image 654
user1471283 Avatar asked Oct 25 '13 07:10

user1471283


1 Answers

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.

like image 199
robertklep Avatar answered Nov 04 '22 00:11

robertklep