MySQL遠端登陸操作

2021-06-21 10:12:16 字數 1748 閱讀 5613

首先在命令列中進入到mysql安裝目錄下的bin路徑,然後就可以使用如下mysql命令:

一、允許root使用者在任何地方通過'youpassword'密碼進行遠端登入,並具有所有庫任何操作許可權,具體操作如下:

在本機先使用root使用者登入mysql:     

mysql -u root -p "youpassword"     

進行授權操作:     

mysql>grant all privileges on *.* to 'root'@'%' identified by 'youpassword' with grant option;     

過載授權表:     

flush privileges;     

退出mysql資料庫:     

exit;

二、允許root使用者在乙個特定的ip進行遠端登入,並具有所有庫任何操作許可權,具體操作如下:

在本機先使用root使用者登入mysql:     

mysql -u root -p"youpassword"     

進行授權操作:     

grant all privileges on *.* to root@"172.16.16.152" identified by "youpassword" with grant option;     

過載授權表:     

flush privileges;     

退出mysql資料庫:     

exit;

三、允許root使用者在乙個特定的ip進行遠端登入,並具有所有庫特定操作許可權,具體操作如下:

在本機先使用root使用者登入mysql:     

mysql -u root -p"youpassword"     

進行授權操作:     

grant select,insert,update,delete on *.* to root@"172.16.16.152" identified by "youpassword";     

過載授權表:     

flush privileges;     

退出mysql資料庫:     

exit;

四、刪除使用者授權,需要使用revoke命令,具體命令格式為:

revoke privileges on 資料庫[.表名] from user-name@host;     

具體例項,先在本機登入mysql:     

mysql -u root -p"youpassword"     

進行授權操作:     

grant select,insert,update,delete on test-db to test-user@"172.16.16.152" identified by "youpassword";     

再進行刪除授權操作:     

revoke all on test-db from test-user@"172.16.16.152";     

****注:該操作只是清除了使用者對於test-db的相關授權許可權,但是這個「test-user」這個使用者還是存在。     

最後從使用者表內清除使用者:     

delete from user where user="test-user" and host="172.16.16.152";     

過載授權表:     

flush privileges;     

退出mysql資料庫:     

exit;

mysql 遠端 mysql遠端登陸

mysql登入方式有兩種,一種是本機登入,一種是遠端登入。這兩種登入方式在mysql資料庫的user表中都有體現。由於我們不可能總是本地登入,因此需要設定遠端登陸。但是mysql預設不支援遠端登陸,所以需要設定一波。1.登入資料庫。2.切換到mysql資料庫。3.檢視主機和使用者對應情況,其實就是檢...

Mysql配置遠端登陸

環境 本地windows 10,遠端ubuntu16.4 mysql5.7 在win10上遠端連線mysql連線不上,首先遠端登陸mysql mysql show databases mysql select user,host,password from mysql.user 這兩步排除資料庫名和...

Mysql 允許遠端登陸

在我們使用mysql資料庫時,有時我們的程式與資料庫不在同一機器上,這時我們需要遠端訪問資料庫。預設狀態下,mysql的使用者沒有遠端訪問的許可權。下面介紹兩種方法,解決這一問題。1 改表法 可能是你的帳號不允許從遠端登陸,只能在localhost。這個時候只要在localhost的那台電腦,登入m...