Search code examples
mysqlsshssh-tunnel

ssh tunnel in foreground works for mysql host localhost and 127.0.0.1 but ssh-tunnel in background doesn't work


So this is similar to my previous question, except now 127.0.0.1 does not work either: ssh tunnel in foreground works for mysql host localhost but ssh-tunnel in background works for mysql host 127.0.0.1

debug1: Authentication succeeded (publickey).
Authenticated to machine-two-hostname.com ([###.##.##.##]:22).
debug1: Local connections to LOCALHOST:3360 forwarded to remote address localhost:3360
debug3: channel_setup_fwd_listener_tcpip: type 2 wildcard 0 addr NULL
debug3: sock_set_v6only: set socket 4 IPV6_V6ONLY
debug1: Local forwarding listening on ::1 port 3360.
debug2: fd 4 setting O_NONBLOCK
debug3: fd 4 is O_NONBLOCK
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 3360.
debug2: fd 5 setting O_NONBLOCK
debug3: fd 5 is O_NONBLOCK
debug1: channel 1: new [port listener]
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: forking to background
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0

It occassionally does "keepalive" which I think is normal:

debug1: client_input_global_request: rtype [email protected] want_reply 1
debug3: send packet: type 82
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 1
debug3: send packet: type 82

The command I ran was:

ssh -vvvvv -fN -L 3360:localhost:3360 [email protected]

all connections through the background ssh tunnel are refused but I can connect fine through the foreground one:

$ mysql -uroot -proot -h127.0.0.1
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")

UPDATE: I am using mysql-client this answer might be related: MYSQL ERROR 2003 (HY000) (113) in SSH remote tunneling, but telnet from SSH tunnel works


Solution

  • I was using port 3360 MySQL is on port 3306.