Connect to MySQL using SSH Tunneling in node-mysql

javascript, mysql, node.js, npm

Solution

You can do the SSH tunnel component completely independently, and then point node-mysql (or any other sql client...) to your DB by using TCP tunneled over SSH.

Just set up your SSH tunnel like this

ssh -N -p 22 sqluser@remoteserverrunningmysql.your.net -L 33306:localhost:3306

Leave that going in the background (see articles like this for more in depth info).

Then just send any MySQL client to port 33306 on localhost. It will actually connect as though you are on your remote server and using port 3306.

Problem

When using the `node-mysql` npm package, is it possible to connect to the MySQL server using a SSH key instead of a password?

Original source