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
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.
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.