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

熱點內容
maya粒子表達式教程 瀏覽:84
抖音小視頻如何掛app 瀏覽:283
cad怎麼設置替補文件 瀏覽:790
win10啟動文件是空的 瀏覽:397
jk網站有哪些 瀏覽:134
學編程和3d哪個更好 瀏覽:932
win10移動硬碟文件無法打開 瀏覽:385
文件名是亂碼還刪不掉 瀏覽:643
蘋果鍵盤怎麼打開任務管理器 瀏覽:437
手機桌面文件名字大全 瀏覽:334
tplink默認無線密碼是多少 瀏覽:33
ipaddgm文件 瀏覽:99
lua語言編程用哪個平台 瀏覽:272
政采雲如何導出pdf投標文件 瀏覽:529
php獲取postjson數據 瀏覽:551
javatimetask 瀏覽:16
編程的話要什麼證件 瀏覽:94
錢脈通微信多開 瀏覽:878
中學生學編程哪個培訓機構好 瀏覽:852
榮耀路由TV設置文件共享錯誤 瀏覽:525

友情鏈接