小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

通過(guò)SSH通道來(lái)訪問(wèn)MySQL

 行者花雕 2020-12-11
 許多時(shí)候當(dāng)要使用Mysql時(shí),會(huì)遇到如下情況:

1. 信息比較重要,希望通信被加密。
2. 一些端口,比如3306端口,被路由器禁用。

對(duì)第一個(gè)問(wèn)題的一個(gè)比較直接的解決辦法就是更改mysql的代碼,或者是使用一些證書(shū),不過(guò)這種辦法顯然不是很簡(jiǎn)單。

這里要介紹另外一種方法,就是利用SSH通道來(lái)連接遠(yuǎn)程的Mysql,方法相當(dāng)簡(jiǎn)單。

一 建立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

現(xiàn)在,你就可以通過(guò)本地連接遠(yuǎn)程的數(shù)據(jù)庫(kù)了,就像訪問(wèn)本地的數(shù)據(jù)庫(kù)一樣。

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來(lái)訪問(wèn)Client的3307端口。

類似的,用PHP訪問(wèn):

<?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.

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多