Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to MySQL using SSH Tunneling in node-mysql

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

like image 960
Nyxynyx Avatar asked Feb 19 '14 23:02

Nyxynyx


1 Answers

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 [email protected] -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.

like image 132
Steven Lu Avatar answered Oct 09 '22 19:10

Steven Lu