在节点MySQL中使用SSH隧道连接到MySQL [英] Connect to MySQL using SSH Tunneling in node-mysql
问题描述
使用 node-mysql
npm软件包时,是否可以连接到MySQL服务器使用SSH密钥而不是密码?
When using the node-mysql
npm package, is it possible to connect to the MySQL server using a SSH key instead of a password?
推荐答案
我今天得到了这个准确的系统,它应该花10分钟,但是我浪费了5个小时来写一个愚蠢的错误(这是我的直接结果)尝试在5分钟内完成该操作).
I got this exact system working today and it should have taken 10 minutes but I wasted 5 hours on a dumb bug I wrote (which was a direct result of me trying too hard to do it in 5 minutes).
您可以完全独立地完成SSH隧道组件,然后使用通过SSH隧道传输的TCP将node-mysql(或任何其他sql客户端...)指向数据库.
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.
只需这样设置您的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).
然后只需将任何MySQL客户端发送到本地主机上的端口33306.实际上,它会好像您在远程服务器上一样并使用端口3306进行连接.
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.
这篇关于在节点MySQL中使用SSH隧道连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!