問題描述
這應該非常簡單,但我無法讓它在我的生活中發揮作用.
我只是想遠程連接到我的 MySQL 服務器.
This should be dead simple, but I cannot get it to work for the life of me.
I'm just trying to connect remotely to my MySQL server.
- 連接方式:
mysql -u root -h localhost -p
- 工作正常,但正在嘗試:
mysql -u root -h 'any ip address here' -p
- 因錯誤而失敗:
ERROR 1130 (00000): Host ''xxx.xx.xxx.xxx'' is not allowed to connect to this MySQL server
在 mysql.user
表中,主機為 'localhost' 的用戶 'root' 和主機為 '%' 的用戶的條目完全相同.
In the mysql.user
table, there is exactly the same entry for user 'root' with host 'localhost' as another with host '%'.
我不知所措,不知道如何繼續.歡迎提出任何想法.
I'm at my wits' end and have no idea how to proceed. Any ideas are welcome.
推薦答案
可能是一種安全預防措施.您可以嘗試添加一個新的管理員帳戶:
Possibly a security precaution. You could try adding a new administrator account:
mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
-> WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
-> WITH GRANT OPTION;
盡管 Pascal 和其他人已經指出,讓具有這種訪問權限的用戶對任何 IP 開放并不是一個好主意.如果您需要管理用戶,請使用 root,并將其保留在 localhost 上.對于任何其他操作,請準確指定您需要的權限,并按照 Pascal 在下面的建議限制用戶的可訪問性.
Although as Pascal and others have noted it's not a great idea to have a user with this kind of access open to any IP. If you need an administrative user, use root, and leave it on localhost. For any other action specify exactly the privileges you need and limit the accessibility of the user as Pascal has suggest below.
來自 MySQL 常見問題:
From the MySQL FAQ:
如果你不明白為什么你會得到訪問被拒絕,從用戶中刪除表所有具有主機的條目包含通配符的值(條目包含 '%' 或 '_' 字符).一種很常見的錯誤是插入一個新的帶有 Host='%' 和的條目User='some_user',認為這個允許您指定 localhost從同一臺機器連接.這這不起作用的原因是默認權限包括帶有 Host='localhost' 和的條目用戶=''.因為該條目有一個 Host值 'localhost' 是更多特定于 '%',它用于優先考慮新條目時從本地主機連接!正確的程序是插入第二個條目與 Host='localhost' 和User='some_user',或者刪除帶有 Host='localhost' 和的條目用戶=''.刪除條目后,記得發出 FLUSH PRIVILEGES語句來重新加載授權表.另見第 5.4.4 節,訪問控制,階段 1:連接驗證".
If you cannot figure out why you get Access denied, remove from the user table all entries that have Host values containing wildcards (entries that contain '%' or '_' characters). A very common error is to insert a new entry with Host='%' and User='some_user', thinking that this allows you to specify localhost to connect from the same machine. The reason that this does not work is that the default privileges include an entry with Host='localhost' and User=''. Because that entry has a Host value 'localhost' that is more specific than '%', it is used in preference to the new entry when connecting from localhost! The correct procedure is to insert a second entry with Host='localhost' and User='some_user', or to delete the entry with Host='localhost' and User=''. After deleting the entry, remember to issue a FLUSH PRIVILEGES statement to reload the grant tables. See also Section 5.4.4, "Access Control, Stage 1: Connection Verification".
這篇關于不允許主機 'xxx.xx.xxx.xxx' 連接到此 MySQL 服務器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!