I need to query a mysql database from one server. The mysql database is located on another network. I can only connect to this network from a specific server.
I need to create a tunnel from server 1, into server 2 and use this tunnel to connect to my mysql database.
This is my current code. This allows me to connect to server 2's local mysql server, but not to a remote mysql server.
var Client = require('ssh2').Client,
mysql = require('mysql2'),
var client = new Client();
var ssh = client.connect({
host: config.server_tunnel.dstHost,
port: 22,
username: config.server_tunnel.username,
privateKey: config.server_tunnel.privateKey
});
ssh.forwardOut('127.0.0.1', 12345, '127.0.0.1', 3306, function (err, stream) {
mysql.createConnection({
user: config.database.username,
password: config.database.password,
database: config.database.database,
stream: stream,
host: 'remote.host.com'
});
});