Connecting To MySQL In Web Service Using SSH

In my web service which is an express api, I connect to a MySQL database hosted on namecheap via SSH2 and then use mysql2 library. When I test this setup locally, it works but on Render, it does not. I get an error saying

Error: connect ECONNREFUSED 127.0.0.1:3306

Here’s my env template

SSH

SSH_HOST=server72.web-hosting.com
SSH_PORT=21098
SSH_USER=<SSH_USER>
SSH_PASSWORD=<SSH_PASS>

Database

DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=<DB_NAME>
DB_USER=<DB_USER>
DB_PASSWORD=<DB_PASS>

The SSH connection is always successful but connecting to the db isn’t.

Hi there,

Is your service on a free plan? If so, unfortunately SSH is not supported for free plan services. You can read more about using SSH with Render services and the various limitations here.

Regards,
Mike


Render Support Engineer, MT (UTC-6)

Hi there,

Just wanted to follow-up on this. I think I may have initially misunderstood what you were trying to do. While free instance type Render services indeed do not support SSH to get into those services, you can still SSH to an external non-Render service.

To accomplish what I think you’re trying to do you will need to open up a SSH tunnel first and then use the mapped port to connect to it.

Hope that helps!

Regards,
Mike


Render Support Engineer, MT (UTC-6)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.