導航:首頁 > 編程大全 > 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資料庫相關的資料

熱點內容
如何讓u盤內文件夾加密 瀏覽:546
window向linux傳文件命令rz 瀏覽:572
文件管理哪個是愛奇藝 瀏覽:516
apk安裝包製作工具 瀏覽:618
別克原車導航升級 瀏覽:383
主板安裝在哪個文件夾 瀏覽:841
迷你編程為什麼一進去沒有任務 瀏覽:92
vv代碼 瀏覽:465
編程為什麼會枯燥 瀏覽:536
如何將文件壓縮成圖片 瀏覽:598
怎麼避開行程卡大數據 瀏覽:839
法學類專業題可用什麼app掃 瀏覽:844
prt轉pdf文件 瀏覽:637
小米4怎麼電腦傳文件 瀏覽:22
5s哪個版本支持三網通 瀏覽:987
導航升級不換主程序 瀏覽:435
資料庫mergesort 瀏覽:870
掃描的文件怎麼保存到電腦 瀏覽:657
不能打開設備和列印機共享文件 瀏覽:239
唱鴨一般下載在哪個文件 瀏覽:540

友情鏈接