I have spent all day trying to solve this. The thing I want to do is that: I have a MYSQL server, namely A with CentOS 7, in a private network, cannot be NAT or connected to VPN. Now I want to access this server from a remote machine, namely B with CentOS 6. I have ssh access to machine B remotely, and ssh access to machine A locally.
This approach I tried is to use SSH tunneling. On machine A terminal:
ssh -R 9001:localhost:3306 user@B
Then on B, I tried
mysql --port=9001 -u root -p
which gives
ERROR 2003 (HY000): Can't connect to MySQL server on 'mysql-server-1' (113)
Firstly I though it could be firewall or privileges, but then I connected A to public network physically with address, say C, which is a different network from B, and I can simpy use from B straight away
mysql -hC -u root -p
and it works without any problem.
Back to tunneling, I tried to telnet after SSH tunneling from A to B
ssh -R 9001:localhost:3306 user@B
telnet localhost 9001
which gives me
Trying ::1...
Connected to localhost.
Escape character is '^]'.
V
5.5.44-MariaDB-log)Gjb+N'u��;cbDkng;1!RXmysql_native_passwordConnection closed by foreign host.
-bash-4.1$
which seems to be something good, but I get the 2003 ERROR anyway.
Any thought of this? Maybe there is another work around to this problem?
P.S. I have tested all answer I could find, and the SSH tunnel works well with socket of other programs.