Question: When using the [`node-mysql`](https://github.com/felixge/node-mysql) npm package, is it possible to connect to the MySQL server using a SSH key instead of a password?

Answer: 
Thanks so much Steve your answer help me alot. just to make it clearer use 

ssh -f user@personal-server.com -L 2000:personal-server.com:25 -N 

The -f tells ssh to go into the background just before it executes the command. This is followed by the username and server you are logging into. The -L 2000:personal-server.com:25 is in the form of -L local-port:host:remote-port. Finally the -N instructs OpenSSH to not execute a command on the remote system

To connect to mongo use whatever port you set as Local port (in this case the port is 2000)

For example let's say I want to connect on a remote server with IP 192.168.0.100 and mongo is running on port 27017. 

Assume a user called elie with password eliepassword has access to ssh on port 22 I will have to do this
First run on the terminal the following : 

ssh -f elie@192.168.0.100 -L 2002:127.0.0.1:27017 -N

In my mongo connection I will do :

var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:2002/mydatabase');

module.exports = mongoose.connection;

I hope this makes it clear.
```
const mysql = require('mysql2');
const { Client } = require('ssh2');
const sshClient = new Client();
const dbServer = {
    host: process.env.DB_HOST,
    port: process.env.DB_PORT,
    user: process.env.DB_USERNAME,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_DATABASE
}
const tunnelConfig = {
    host: process.env.DB_SSH_HOST,
    port: 22,
    username: process.env.DB_SSH_USER,
    password: process.env.DB_SSH_PASSWORD
}
const forwardConfig = {
    srcHost: '127.0.0.1',
    srcPort: 3306,
    dstHost: dbServer.host,
    dstPort: dbServer.port
};
const SSHConnection = new Promise((resolve, reject) => {
    sshClient.on('ready', () => {
        sshClient.forwardOut(
        forwardConfig.srcHost,
        forwardConfig.srcPort,
        forwardConfig.dstHost,
        forwardConfig.dstPort,
        (err, stream) => {
             if (err) reject(err);
             const updatedDbServer = {
                 ...dbServer,
                 stream
            };
            const connection =  mysql.createConnection(updatedDbServer);
           connection.connect((error) => {
            if (error) {
                reject(error);
            }
            resolve(connection);
            });
});
}).connect(tunnelConfig);
});

```