使用SSH通道访问MySQL的方法

许多时候当要使用MySQL时,会遇到如下情况:

创新互联公司是专业的范县网站建设公司,范县接单;提供成都网站设计、网站制作、外贸营销网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行范县网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

1. 信息比较重要,希望通信被加密。

2. 一些端口,比如3306端口,被路由器禁用。

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

相关学习视频教程推荐: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
The command tells the local MySQL client to connect to localhost port 3307 (which is forwarded via ssh to remotehost.com:3306). The exchange of data between client and server is now sent over the encrypted ssh connection.

或者用Mysql Query Brower来访问Client的3307端口。

类似的,用PHP访问:


Making It A Daemon
A quick and dirty way to make sure the connection runs on startup and respawns on failure is to add it to /etc/inittab and have the init process (the, uh, kernel) keep it going.
Add the following to /etc/inittab on each client:
sm:345:respawn:/usr/bin/ssh -Ng -L 3307:127.0.0.1:3306 myuser@remotehost.com
And that should be all you need to do. Send init the HUP signal ( kill -HUP 1 ) to make it reload the configuration. To turn it off, comment out the line and HUP init again.

以上就是详解如何通过SSH通道来访问MySQL的详细内容,更多请关注创新互联其它相关文章!


网页名称:使用SSH通道访问MySQL的方法
文章源于:http://bzwzjz.com/article/iieghe.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 企业网站设计 成都定制网站建设 网站建设 成都模版网站建设 成都网站建设公司 商城网站建设 成都h5网站建设 企业网站建设公司 成都网站建设 四川成都网站建设 营销型网站建设 成都网站设计 温江网站设计 成都网站建设公司 手机网站建设套餐 成都网站设计 网站建设方案 网站建设公司 企业网站建设 四川成都网站制作 自适应网站建设 定制网站建设