通过ssh隧道访问mysql

许多时候当要使用Mysql时,会遇到如下情况:
1. 信息比较重要,希望通信被加密。
2. 一些端口,比如3306端口,被路由器禁用。

对第一个问题的一个比较直接的解决办法就是更改mysql的代码,或者是使用一些证书,不过这种办法显然不是很简单。

这里要介绍另外一种方法,就是利用SSH通道来连接远程的Mysql,方法相当简单。

一 建立SSH通道

只需要在本地键入如下命令:

ssh -fNg -L 3307:127.0.0.1:3306 [email protected]

The command tells ssh to log in to remotehost.com as myuser, go into the background (-f) and not execute any remote command (-N), and set up port-forwarding (-L localport:localhost:remoteport ). In this case, we forward port 3307 on localhost to port 3306 on remotehost.com.

二 连接Mysql

现在,你就可以通过本地连接远程的数据库了,就像访问本地的数据库一样。

mysql -h 127.0.0.1 -P 3307 -u dbuser -p db

或者通过navicat像链接本地mysql一样   就ok




实现用本地的ssh隧道起到加密功能

在windows平台上运行Navicat for MySQL(http://www.navicat.com/  )

1、连接connetcion进去设置

设置windows本地数据库账户和密码

2、

连接  linux平台ssh,设置服务器的账户和密码

上面配置好后,点击左下角的Test Connetion测试是否成功

利用Linux平台之间的隧道连接在研究中~即将献上配置文章

本文出自 “Holy” 博客,请务必保留此出处http://holy2010.blog.51cto.com/1086044/518431


猜你喜欢

转载自blog.csdn.net/yilukuangpao/article/details/79225295
今日推荐