
- #NODEJS MYSQL SSH TUNNEL HOW TO#
- #NODEJS MYSQL SSH TUNNEL MANUAL#
- #NODEJS MYSQL SSH TUNNEL CODE#
- #NODEJS MYSQL SSH TUNNEL MAC#
SSH -L connection successful, but localhost port forwarding not working "channel 3: open failed: connect failed: Connection refused" So some sort of request was getting successfully sent to my remote server. How exactly does one "connect your node.js app to localhost"? I saw that on the remote server side, I was getting channel 3: open failed: connect failed: Connection refused. Because with that ssh command in screen you make port 3306 from mysql server available on your local machine

#NODEJS MYSQL SSH TUNNEL CODE#
I'm receiving: Is there a step here that I missed? I'm able to query successfully with this code on servers that don't require ssh.Īnd the response led me somewhere but did not completely explain what I need to do:Īfter you connected via ssh you need to connect your node.ja app to localhost. However, when I run my server.js node file the problem still persists.
#NODEJS MYSQL SSH TUNNEL MAC#
I'm using a mac terminal, I typed 'screen', entered in the information you provided with my domain and password,and succesfully connected into my server via ssh. A comment below the accepted answer had the same issue: So I started a "screen" session, connected with the ssh command, and created the connection in a node script.
#NODEJS MYSQL SSH TUNNEL HOW TO#
here 127.0.0.Starting from scratch, I googled how to connect to a mysql database over ssh using node.js and the mysql library, and I came across this: Now your (client side) mysql client is conected to remote mysql server. CLIENT SIDE - mysql -h 127.0.0.1 -P 1000 -u mysql_user -pmysql_pass Which means there is a permanent connection through shh protocol tcp 0 0 server_ip:22 clint_ip:port ESTABLISHED 24915/sshd: user_name You'll get 'ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)' when trying co connect mysqlīoth -f -N kind of nohoop - you can close console and tunnels persist 127.0.0.1 means here the remote (host_name) and should not be replaced with localhost word because this will make the connection on unix (named) socket not by IP. You have an account (eventualy a ssh-key) to log using cygwin,putty or a linux_shell ssh SSH TUNNEL ssh -f -N -L 1000:127.0.0.1:3306 means hey ssh create a permanent connection from port 1000 on the machine that I type (client) to remote host_name:3306. Which means mysql server will respond only to request from the localhost In target machine (that can be addresed by IP or a domain hosted) there is config file /etc/mysql/my.cnf having a line bind-address = 127.0.0.1Ĭonfirmed with console netstat -tapn | grep mysql
#NODEJS MYSQL SSH TUNNEL MANUAL#
You probably did not create a user being unreachable from my location at this time, I cannot link to the relevant manual pages. MySQL access control checks both the username/password ( user) and the origin of the connection ( host) to identify a user.

(replace 'user', after the LIKE clause, with the actual user name if necessary) mysql > SELECT user, host FROM er WHERE user LIKE 'user' OR host LIKE 'localhost' Since your server does not listen to 127.0.0.1 (see previous paragraph), the SSH tunnel cannot be established, connection fails, and your client interprets it as a network failure.ģ - Why mysql -v -h localhost -P 9989 -u user userdb -p fails I suspect SSH tunnel is actually established only when it receives a connection request (in your case, when you run the mysql client). The reason for you error ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 is not obvious to me. You may want to use bind-address=0.0.0.0, which instructs MySQL daemon to listen to all network interfaces. Remove one redundant bind-address clause. The reason why you can connect with -h localhost but not with -h 127.0.0.1 is that in the first form, you do not actually connect through TCP/IP, but through a local socket. The first bind-address clause is overridden (therefore, ignored) by the second one.

You cannot bind MySQL to more than one specific IP.
