導航:首頁 > 編程大全 > mysqlssh資料庫

mysqlssh資料庫

發布時間:2025-02-07 07:16:07

A. 如何通過SSH通道來訪問MySQL


許多時候當要使用Mysql時,會遇到如下情況: 出於資料庫的安全性,資料庫管理員在配置資料庫時會為資料庫增加一層保護傘,保護用戶在連接資料庫時的安全和信息不被泄漏,通常的做法就是配置SSH,也就是為資料庫增加一個安全協議,這也導致了用戶進行遠程連接



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

出於資料庫的安全性,資料庫管理員在配置資料庫時會為資料庫增加一層“保護傘”,保護用戶在連接資料庫時的安全和信息不被泄漏,通常的做法就是配置SSH,也就是為資料庫增加一個安全協議,這也導致了用戶進行遠程連接時的困難。
1. 信息比較重要,希望通信被加密。
2. 一些埠,比如3306埠,被路由器禁用。

對第一個問題的一個比較直接的解決辦法就是更改mysql的代碼,或者是使用一些證書,不過這種辦法顯然不是很簡單。

這里要介紹另外一種方法,就是利用SSH通道來連接遠程的Mysql,方法相當簡單。

一 建立SSH通道

例如:

遠程Mysql伺服器ip:172.21.20.203

mysql埠號:3307 用戶名:test 密碼:123456

SSH通道IP:117.123.52.161 埠:79

用戶名:admin

通過navicat for mysql客戶端工具,

通常我們普通連接就是如下:



點擊連接測試:彈出錯誤框,由於添加了SSH協議!所以我們要使用SSH通道,如下圖:



這時候點擊連接測試,,可以連接進去,Test Success.

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

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

例如:我們在終端輸入:

ssh -fNg -p 79 -L 8989:172.21.20.203:3307 [email protected]

現在,你就可以通過本地連接遠程的資料庫了,就像訪問本地的資料庫一樣。



點擊連接,Test Success

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 [email protected]

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.

閱讀全文

與mysqlssh資料庫相關的資料

熱點內容
電腦怎麼手動獲取網路 瀏覽:317
五行生財app如何 瀏覽:541
文件管理圖標丟失 瀏覽:500
返利網站怎麼經營 瀏覽:738
plc編程時有什麼技巧 瀏覽:276
小蘋果爵士 瀏覽:156
鏡像助手找不到boot文件 瀏覽:506
桌面保護密碼怎麼設置 瀏覽:895
smit工具的log文件有哪些 瀏覽:883
做網站運營要多少錢 瀏覽:933
放在桌面上的文件在c盤 瀏覽:530
哪個app的東西是專櫃的 瀏覽:380
韓劇在哪裡看app 瀏覽:40
規范性文件的審批程序包括哪些 瀏覽:751
項目負責人簽署的文件有哪些 瀏覽:659
iphoe6升級後id驗證失敗 瀏覽:105
鴻蒙系統手機文件哪些可以刪除 瀏覽:983
90版本貪食之痕怎麼做 瀏覽:261
datedatetimejava 瀏覽:392
招貼的源文件格式是什麼 瀏覽:273

友情鏈接