cd /mysql的安裝目錄/bin
創(chuàng)新互聯(lián)公司專注于花垣企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計(jì),電子商務(wù)商城網(wǎng)站建設(shè)。花垣網(wǎng)站建設(shè)公司,為花垣等地區(qū)提供建站服務(wù)。全流程按需求定制制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
mysql -u root -p
然后輸入密碼,再用 use XXX; 來選擇數(shù)據(jù)庫,哦,show databases; 是顯示所有數(shù)據(jù)庫
協(xié)議不一樣無法直接連接的。
可以ssh連接到mysql數(shù)據(jù)庫服務(wù)器上,然后再使用本機(jī)的mysql客戶端連接到數(shù)據(jù)庫上面。
你說的是
ssh( Secure Shell )還是ssh(Spring + Struts +Hibernate)
您好,希望以下回答能幫助您
連接MYSQL:
格式: mysql -h主機(jī)地址 -u用戶名 -p用戶密碼
1、例1:連接到本機(jī)上的MYSQL
找到mysql的安裝目錄,一般可以直接鍵入命令mysql -uroot -p,回車后提示你輸密碼,如果剛安裝好MYSQL,超級(jí)用戶root是沒有密碼的,故直接回車即可進(jìn)入到MYSQL中了,MYSQL的提示符是:mysql
2、連接到遠(yuǎn)程主機(jī)上的MYSQL
假設(shè)遠(yuǎn)程主機(jī)的IP為:10.0.0.1,用戶名為root,密碼為123。則鍵入以下命令:
mysql -h10.0.0.1 -uroot -p123
(注:u與root可以不用加空格,其它也一樣)
3、退出MYSQL命令
exit (回車)
如您還有疑問可繼續(xù)追問。
$host='127.0.0.1';
$user='root';
$password='root';
$dbName='dbName';
$link=new mysqli($host,$user,$password,$dbName);
if ($link-connect_error){
die("連接失敗:".$link-connect_error);
}
$sql="select * from admins";
$res=$link-query($sql);
$data=$res-fetch_all();
var_dump($data);
許多時(shí)候當(dāng)要使用Mysql時(shí),會(huì)遇到如下情況:
1. 信息比較重要,希望通信被加密。
2. 一些端口,比如3306端口,被路由器禁用。
對(duì)第一個(gè)問題的一個(gè)比較直接的解決辦法就是更改mysql的代碼,或者是使用一些證書,不過這種辦法顯然不是很簡單。
這里要介紹另外一種方法,就是利用SSH通道來連接遠(yuǎn)程的Mysql,方法相當(dāng)簡單。
一 建立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)在,你就可以通過本地連接遠(yuǎn)程的數(shù)據(jù)庫了,就像訪問本地的數(shù)據(jù)庫一樣。
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.
下載navicat或者別的工具。windows需要下載freesshd安裝ssh服務(wù)。linux自帶,需要啟動(dòng)ssh服務(wù)。然后用navicat進(jìn)行連接,需要注意的是,常規(guī)連接的是mysql這個(gè)數(shù)據(jù)庫,ssh連接的是ssh服務(wù)器所在的地址。具體操作百度即可
本文名稱:ssh怎么用mysql庫 ssh框架怎么實(shí)現(xiàn)對(duì)數(shù)據(jù)庫的訪問
文章路徑:http://chinadenli.net/article10/hgdido.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、企業(yè)網(wǎng)站制作、網(wǎng)站策劃、網(wǎng)站營銷、用戶體驗(yàn)、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容