SSH通道来建立安全连接

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

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

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

一 建立SSH通道

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

ssh -fNg -L 3307:127.0.0.1:3306 myuser@remotehost.com

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

 https://blog.csdn.net/yilukuangpao/article/details/79225295

原文地址:https://www.cnblogs.com/youxin/p/12996254.html