问题描述
我已经花了一整天的时间来解决这个问题.我想做的是:我在专用网络中有一个MYSQL服务器,即带有CentOS 7的A,无法进行NAT或连接到VPN.现在,我想从远程计算机(即具有CentOS 6的B)访问该服务器.我可以通过ssh远程访问计算机B,并且可以通过ssh本地访问计算机A.
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.
我尝试过的这种方法是使用SSH隧道.在机器A终端上:
This approach I tried is to use SSH tunneling.On machine A terminal:
ssh -R 9001:localhost:3306 user@B
然后在B上,我尝试了
mysql --port=9001 -u root -p
给出
ERROR 2003 (HY000): Can't connect to MySQL server on 'mysql-server-1' (113)
首先,我虽然可能是防火墙或特权,但后来我将A物理连接到地址为C的公共网络,该地址与B是不同的网络,我可以立即从B简化使用情况
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
它可以正常工作.
回到隧道,从A到B的SSH隧道连接后,我尝试通过telnet
Back to tunneling,I tried to telnet after SSH tunneling from A to B
ssh -R 9001:localhost:3306 user@B
telnet localhost 9001
这给了我
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$
这似乎不错,但是无论如何我还是收到2003错误消息.
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.我已经测试了所有可以找到的答案,并且SSH隧道可以与其他程序的套接字配合使用.
P.S. I have tested all answer I could find, and the SSH tunnel works well with socket of other programs.
推荐答案
请确保您试图通过VPN访问mysql的本地计算机的IP地址具有访问数据库的特权.
make sure that the IP address of your local machine, from which you are trying to access mysql through VPN has privileges to access the database.
mysql> select host,user,password from mysql.user;
+------+------+-------------------------------------------+
| host | user | password |
+------+------+-------------------------------------------+
| % | abcd | *9B3E7610FB431631340BD618E58D49DF1928A251 |
| % | sync | *1747319F3F87039C382597515F8742920D9B75D1 |
| % | root | *FAAFFE644E901CFAFAEC7562415E5FAEC243B8B2 |
+------+------+-------------------------------------------+
确保为您要登录的用户提供一个本地计算机IP地址的条目.您也可以在主机字段中使用%. %表示所有用户.
Make sure that there is an entry for the ip address of local machine for the user through which you are logging in. You can also use % in the host field. % denotes all users.
您可以通过以下命令添加权限
You can add privileges through the following command
mysql> grant all on *.* to 'root'@'%' identified by <password>.
mysql> flush privileges
这篇关于SSH远程隧道中出现MYSQL ERROR 2003(HY000)(113),但SSH隧道中的telnet有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!