gpt4 book ai didi

mysql - 主机 'xxx.xx.xxx.xxx' 不允许连接到这个 MySQL 服务器

转载 作者:IT老高 更新时间:2023-10-28 12:47:25 25 4
gpt4 key购买 nike

这应该很简单,但我无法让它为我的生活工作。
我只是想远程连接到我的 MySQL 服务器。

  • 连接为:

    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' 的条目与主机为 '%' 的另一个条目完全相同。

我束手无策,不知道如何继续。欢迎任何想法。

最佳答案

可能是一种安全预防措施。您可以尝试添加一个新的管理员帐户:

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 的建议限制用户的可访问性。

编辑:

来自 MySQL 常见问题解答:

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”.

关于mysql - 主机 'xxx.xx.xxx.xxx' 不允许连接到这个 MySQL 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1559955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com