Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js使用隧道ssh建立到远程mysql服务器的连接_Mysql_Node.js_Ssh - Fatal编程技术网

Node.js使用隧道ssh建立到远程mysql服务器的连接

Node.js使用隧道ssh建立到远程mysql服务器的连接,mysql,node.js,ssh,Mysql,Node.js,Ssh,我正在使用tunnel ssh模块使用node.js建立到远程mysql数据库的连接。文档很差,我无法建立连接。以下是代码片段: var tunnel = require('tunnel-ssh') var server = tunnel.tunnel(config.sshData, function(err, result) {console.log('connected'}); 这是我的sshData对象 config.sshData = {host : 'serverxyz.web-ho

我正在使用
tunnel ssh
模块使用node.js建立到远程
mysql
数据库的连接。文档很差,我无法建立连接。以下是代码片段:

var tunnel = require('tunnel-ssh')
var server = tunnel.tunnel(config.sshData, function(err, result) {console.log('connected'});
这是我的sshData对象

config.sshData = {host : 'serverxyz.web-hosting.com', username : 'xyz', password : 'xyz',
srcPort: 3307, dstPort : 21098}
如建议的那样,
dsport
21098

但是,我遇到超时错误,每当我添加此代码段时:

server.on('error', function(err) {});
我得到错误
server.on不是一个函数
。远程连接在
putty
SQLyog
上正常工作。任何关于如何建立成功连接的程序都会大有帮助。谢谢

更新


使用指定的正确端口和直接使用
ssh2
模块使数据库正常工作,给出了代码示例

文档中存在误解。21098是ssh端口,而不是数据库正在侦听的端口。为了使用非标准ssh端口,您需要明确指定
端口
值,如下所示:

config.sshData = {
  host: 'serverxyz.web-hosting.com',
  port: 21098,
  username: 'xyz',
  password: 'xyz',
  dstPort: 3306
};

然后您应该能够连接到
localhost:3306
以访问远程数据库。

我认为dstPort是数据库可用的端口。因此,如果数据库在localhost:3307上运行,那么请使用
dstPort:3307
我使用了答案中指定的正确端口号,仍然收到超时错误感谢您的回复。即使使用指定的正确端口,我也会收到超时错误<代码>事件.js:141抛出器;//未处理的“error”事件^error:等待握手时在null处超时。_onTimeout(..\node\u modules\tunnel ssh\node\u modules\ssh2\lib\client.js:569:19)在Timer.listOnTimeout(timers.js:92:15)如前所述,我能够连接到远程主机并执行
正常运行时间。任何关于如何进行的想法都会大有裨益!我从你的代码()