Access MySQL through SSH [GOT CREATED]

Hi, I am having issues accessing MySQL through n8n.
I looked through the forum for someone with similar issues as it could be my lack of skills.
I can access it through the terminal but for some reason it doesn’t work on n8n.

I first open the SSH session

Here is how I access MySQL through the terminal;

I have copy pasted all the credentials so their are identical in n8n, I then point it to the 3336 port I connected in the SSH session.

When I try to run a query I get connection time out.

Does anyone know the issue?
Thanks for all the help!

So I understand it correctly that you create an SSH tunnel and so redirect the local traffic to the remote MySQL server? In this case should the “Host” in the credentials not be “localhost”?

1 Like

The MySQL host is different from the SSH host.
I first connect to an SSH IP e.g [email protected] once I have access to I can then request access with;
~$ mysql -u User_Name -p -h

This is how I access it through Sequel Pro

Honestly do not have much experience in this. But what an SSH tunnel does is to redirect all local traffic from a local port to another or the same port of an external server.

So as described here:

And there it then also says to connect now to
If there are totally different servers and if sending traffic to the port of the SSH server does not end up on the MySQL server I honestly do not know how to connect to it. Again have sadly no experience. But is also not a directly to n8n related question, rather a more generic one. So I guess if you do some more googling you find a solution that would also work with n8n.

Thanks Jan, fully understandable. I was most curious about the Mysql node on n8n. Perhaps the issue is there on how it forwards its requests and perhaps one could add the SSH tunneling in like Sequel pro to make it easier.

I found the solution. Is it a possible to work with the ssh2 node mentioned here together with n8n?

I’m looking for this feature too, because for run remote commands such as mysql querys in another host is secure regarding access another environment to use some workflows.

In my case I`m creating workflow to access management, using JIRA Service Desk as input, to give access creating users in MYSQL instance and give access in databases.

Did someone manage to get this working. I am currently looking for a solution to this problem as well. Would need to be able to connect to our MySQL server over a SSH connection.

Change this post to a feature request. You can now upvote it. The more votes, the more chances of being developed.


I was also trying to find if MySQL node can connect through SSH. Sadly still is not happening.

This is great scenario because some hosts do not expose the mysql service, only local, so that you have to connect via SSH first.

I too found this example here

Hope you guys pick it up some day.


Hey @Mulen,

A possible solution might be to create the SSH tunnel first then do the connection that is how I would do it from my desktop.

I have never tried it in n8n but in theory adding the ssh client to the docker image then making the tunnel in an execute command node with -L and just sending the output to /dev/null would then allow the MySQL node to work by connecting to localhost and whatever port gets directed.

It would cleaner to have this in the node directly though.

Hello @Jon

I don’t thing it would work. How MySQL node would know the host? For the credentials at the Host field you have to specify localhost or But to do this there must be a connection from n8n to the host via a ssh tunnel or a VPN outside the n8n container.

To work the same concept as other MySQL IDEs has to be applied that they allow to use SSH Tunnel via the app.

Hey @Mulen,

The Node would connect to localhost, So with an SSH tunnel you open an SSH session between your machine and the remote server and you forward a local port to the port you want on the remote side.

So if you were to run…

ssh -N -L 3307: [email protected]

You would be setting up your local port 3307 to be the remote host and port of so in your MySQL node it would point to localhost and port 3307 and with the magic of the tunnel it will translate that to the localhost of the remote machine and port 3306.

Assuming the tunnel is opened in the container if you are using one it should do the job, If you are using npm instead in theory it is a lot easier as you just need to make the tunnel connection on your machine.

@Jon I think i am almost there.

You are right. I opened 2 ssh consoles on the server running mysql.

At the first console i connected to the same server again via

ssh -N -L 3307: root@<IP_ADDRESS>

At the second console i typed

mysql --port=3307 --host= --user=wordpress --password wordpress

and connected successfully.

The thing is i can’t from n8n docker now connect it.

At the localhost field i tried the host docker ip and the port 3307 but getting connection refused.

Hey @Mulen,

You would need to start the tunnel from inside the container for best results, If you are trying it on the docker host maybe using ssh -N -L would do the job.


Omg. It works. It’s just like witchcraft. Can’t thank you enough!

1 Like

No problem @Mulen :+1:

I have given this feature request an up vote. @Jon 's solution works perfectly on a local Docker install, but not on the Cloud (as far as I can think of) … unless I would be able to setup/configure this in my instance? I am in the process of migrating all the critical production processes to the Cloud and leave my local Docker as development and fall-back environment. So a proper ‘MySQL over SSH’ connection would be ideal for that.

1 Like

Hey @maartend,

You got it, The workaround won’t work on Cloud at the moment. I am not sure how much work would be involved in adding in the SSH option to the node but I suspect it would involve having to create an SSH tunnel in the node first as I don’t like the package we use has it an option to just enable.

Good news, We recently added support for MySQL and Postgres to allow connections over SSH Tunnels.