1. 程式人生 > >解決mysql本地可訪問,遠端無法訪問的問題 Host is not allowed to connect to this MySQL server

解決mysql本地可訪問,遠端無法訪問的問題 Host is not allowed to connect to this MySQL server

解決方法:

  1. 改表法。可能是你的帳號不允許從遠端登陸,只能在localhost。這個時候只要在localhost的那臺電腦,登入mysql後,更改 “mysql” 資料庫裡的 “user” 表裡的 “host” 項,從”localhost”改稱”%”
mysql>mysql -u root -p;
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
  1. 授權法。例如,你想root使用mypassword從任何主機連線到mysql伺服器的話。

允許root使用者在任何地方均可連結:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

如果你想允許使用者root從ip為特定IP(如192.168.1.3)的主機連線到mysql伺服器,並使用mypassword作為密碼

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

通過任意一種方式進行修改時,要重啟MySQL服務,方能生效

文章首次釋出於 吾勇士的部落格 http://wuyongshi.top/articles/2017/05/13/1494679617739.html

借鑑文章:http://chen3888015.blog.51cto.com/2693016/986841
http://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server