mysql允許外部連線

2021-07-05 08:01:09 字數 1541 閱讀 7259

mysql為了安全性,在預設情況下使用者只允許在本地登入,可是在有此情況下,還是需要使用使用者進行遠端連線,因此為了使其可以遠端需要進行如下操作:

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

在本機先使用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;

具體例項,先在本機登入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;

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

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

delete from user where user="test-user";

過載授權表:

flush privileges;

退出mysql資料庫:

exit

設定mysql允許外部連線訪問

錯誤資訊 sql error 1130 host 192.168.1.88 is not allowed to connect to this mysql server 說明所連線的使用者帳號沒有遠端連線的許可權,只能在本機 localhost 登入。需更改 mysql 資料庫裡的 user表裡的 ...

MySQL允許外部訪問

進入mysql資料庫 use mysql 更新域屬性,表示允許外部訪問 update user set host where user root 注意,這裡可以select檢視一下user root 的主機都有那些,如果有localhost以及127.0.0.1的話,最好delete掉,只保留主機為...

mysql允許外部IP訪問

預設情況下linux內的mysql資料庫mysql,user表內的使用者許可權只是對localhost即本機才能登陸。需要更改許可權 mysql grant all privileges on to root identified by password with grant option 表示是所...