Mysql數據庫遠程授權
如果mysql不支持遠程連接,會出現提示:錯誤代碼是1130,ERROR 1130: Host 192.168.0.10 is not allowed to connect to this MySQL server ,解決此問題有以下2個方法:
1、改表法:在本機登入mysql后,更改“mysql”數據庫里的“user”表里的“host”項,從”localhost”改為'%'。
mysql> mysql>use mysql; mysql>select 'host' from user where user='root'; #查看mysql庫中的user表的host值(即可進行連接訪問的主機/IP名稱) mysql>update user set host = '%' where user ='root'; #修改host值(以通配符%的內容增加主機/IP地址,當然也可以直接增加某個特定IP地址,如果執行update語句時出現ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 錯誤,需要select host from user where user = 'root'; |
查看一下host是否已經有了%這個值,如果有了直接執行下面的flush privileges;即可)
mysql>flush privileges; mysql>select host,user from user where user='root'; mysql>quit |
退出后會回到DOS正常的提示符狀態,此時可以通過遠程連接Mysql了!
========================================
2. 授權法。例如,你想myuser使用mypassword從任何主機連接到mysql服務器的話。
為mysql創建一個遠程連接用戶:
grant all privileges on *.* to remoteuser@remoteIPAddr identified by 'password'; (remoteIPAddr是指遠程客服端ip)
例如:grant all privileges on *.* to myuser@192.168.0.10 identified by 'shihuan';
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允許用戶myuser從ip為192.168.0.10的主機連接到mysql服務器,并使用mypassword作為密碼
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.0.10' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
我的mysql.user里root用戶的host果然是localhost,先用改表法給localhost改成“%”,還是不行,仍然報1130的錯誤,又按“從任何主機連接到mysql服務器”方法授權,還是報一樣的錯,最后給自己的ip授權之后,終于登錄上了。
posted on 2014-02-14 11:40 順其自然EVO 閱讀(986) 評論(0) 編輯 收藏 所屬分類: 數據庫