node mysql ssh,使用node-mysql中的SSH隧道连接到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?

解决方案

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).

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值