Sequelize connection over ssh

前端 未结 1 781
谎友^
谎友^ 2021-02-10 07:04

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 se

相关标签:
1条回答
  • 2021-02-10 07:12

    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.

    0 讨论(0)
提交回复
热议问题