MySQL 設定遠端訪問

2021-07-25 23:38:00 字數 1715 閱讀 9762

mysql遠端訪問,也就是通過ip訪問mysql服務,mysql對於安全的要求是非常嚴格的,需要授權。 

1.本地訪問

sql**  

grantallprivilegeson*.*toadmin@localhost identifiedby'admin'withgrantoption;   

flushprivileges;  

上述命令的意思是為admin使用者授權,以localhost方式訪問資料庫,密碼為admin,這是我們推薦的訪問方式,不直接暴露ip,提高資料庫伺服器的安全性。 

2.遠端訪問

如果資料庫伺服器與應用伺服器物理層面分割,也就是不在同一臺伺服器的時候,我們需要通過ip方式訪問,這個ip就是資料庫伺服器主機ip。 

sql**  

grantallprivilegeson*.*to[email protected] identifiedby'admin'withgrantoption;   

flushprivileges;  

當然,這裡授予admin使用者with grant option許可權,欠穩妥!如果乙個使用者從遠端登入修改了資料庫表結構等等,是非常有風險的! 

通常不建議授予授予其他使用者許可權權力,即: 

sql**  

grantallprivilegeson*.*to[email protected] identifiedby'admin';   

flushprivileges;  

3.任意訪問

如果不限制ip訪問,授權某個使用者可以以任意ip訪問該服務,可以這樣寫: 

sql**  

grantallprivilegeson*.*toadmin@'%' identifiedby'admin';   

flushprivileges;  

注意單引號!

3.取消授權

當然,有授權,就一定有取消授權: 

sql**  

revokeallon*.*from[email protected];   

flushprivileges;  

ok,現在我們可以開始部署我們的應用了!

mysql設定遠端訪問

1.使用命令 mysql u 使用者名稱 p密碼,登入mysql 2.執行命令 grant all privileges on to root identified by zmp 123456 with grant option 3.執行命令 flush privileges 4.執行命令 exit...

mysql設定遠端訪問

步驟3 配置遠端訪問mysql 修改 mysql 的配置檔案,執行如下命令 sudo vi etc mysql mysql.conf.d mysqld.cnf 43 注意 其他 linux系統 可能在 etc mysql my.cnf 找到 bind address 127.0.0.1 這一行要注釋...

mysql設定遠端訪問

1.修改資料庫用root給遠端訪問 登入資料庫 mysql u root pvmwaremysql use mysql 為所有ip都可以遠端訪問 mysql update user set host where user root 或直接新增一條語句也行 mysql insert into user...