站長資訊網
        最全最豐富的資訊網站

        詳解如何通過SSH通道來訪問MySQL

        詳解如何通過SSH通道來訪問MySQL

        許多時候當要使用Mysql時,會遇到如下情況:

        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訪問:

        <?php $smysql = mysql_connect( "127.0.0.1:3307", "dbuser", "PASS" ); mysql_select_db( "db", $smysql ); ?> 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.

        贊(0)
        分享到: 更多 (0)
        網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
        主站蜘蛛池模板: 久久精品亚洲精品国产色婷| 国产亚洲精品a在线无码| 亚洲国产精品嫩草影院久久 | 最新精品露脸国产在线 | 国产精品最新国产精品第十页 | 国产精品无码v在线观看| 国产精品美女一区二区视频 | 久久精品视屏| 91热成人精品国产免费| 国产欧美日韩精品丝袜高跟鞋| 亚洲一区二区精品视频| 精品无码综合一区| 国产精品男男视频一区二区三区| 97r久久精品国产99国产精| 少妇人妻偷人精品视频| 亚洲AV成人精品日韩一区18p| 国产精品高清在线| 99久久精品无码一区二区毛片| 国产精品久久久久aaaa| 精品国精品无码自拍自在线| 在线精品动漫一区二区无广告| 九九久久精品国产| 精品乱子伦一区二区三区| 国产99视频精品专区| 93精91精品国产综合久久香蕉 | 久久精品亚洲中文字幕无码麻豆 | 国产91在线精品| 国产高清在线精品一本大道国产| 亚洲精品性视频| 99精品国产成人一区二区| 麻豆精品久久久一区二区| 国产精品福利在线播放| 精品福利一区二区三| 精品视频一区二区三区在线观看| AAA级久久久精品无码片| 69SEX久久精品国产麻豆| 国产成人精品男人的天堂538| 华人亚洲欧美精品国产| 99久久www免费人成精品| 国产福利电影一区二区三区,亚洲国模精品一区 | 亚洲精品成人片在线观看精品字幕|