DEV Community

Discussion on: Connecting to db with nodejs

Collapse
 
mihranh profile image
MihranH • Edited

Thanks for contact!. I can connect with terminal and mysql workbench but not with node. The db engine is innoDB.

Collapse
 
brandinchiu profile image
Brandin Chiu

Next most likely culprit would be your ORM configuration. Have you worked with these packages before?

Thread Thread
 
mihranh profile image
MihranH

Yes. I can connect to a db located in the server which I connect via ssh and I do this with the same packages. However this time the db is not in the same server as the server I connect via ssh.

Thread Thread
 
brandinchiu profile image
Brandin Chiu

So your application is on Server A, which you can ssh into, and your database is on Server B.

You can connect to the database server via MySQL workbench from your local system, and you mentioned you can connect to the database via the command line.

Is the command line connection initiated locally or from Server A?

Where are your servers hosted? Is it a cloud service or custom install?

Thread Thread
 
mihranh profile image
MihranH • Edited

The command line connection initiated locally. From my local terminal I can ssh into server A and then enter server B. DB on server B is accessible only from server A via login password. The servers are custom install.

Thread Thread
 
brandinchiu profile image
Brandin Chiu

It sounds like you're connecting to server A via ssh, then connecting to server B via ssh, and then connecting to the database from the command line on server B.

If this is true, then this won't be an effective troubleshooting step.

Instead, ssh into server A, and then try to connect to the database server (not the computer it's running on) via the mysql command line on server A.

  • ssh into server A
  • run mysql -h IP_ADDRESS_OF_SERVER_B -u MYSQL_USERNAME -PPASSWORD

Note that there is no space between the -P and the password. A live example might look like: mysql -h 35.123.0.10 -u myUser -PreallySecurePassword123

If you can connect successfully using the above, then your connection details in your code (through your ORM/DB configuration) are wrong.

If you can't connect using the above, then there are network issues like a firewall that is blocking traffic either incoming or outgoing between server A and server B.

Your next step would be to troubleshoot that by reviewing the networking setup of those two machines, using pings or traceroutes as a starting point.

Thread Thread
 
mihranh profile image
MihranH

Yes, it seems the code part has issues. CMD ssh and mysql part were done the way you said and they worked. Thanks a lot and will come back with more questions if needed!