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

标签 mysql mysql-error-1130

这应该非常简单,但我无法让它为我的生活工作。
我只是想远程连接到我的 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”与主机为“%”的用户“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/22143126/

相关文章:

mysql - Node util promisify mysql 类型错误

php - 我的 SQL 查询有什么问题?

Java/MySQL 结果集中途出现空指针异常

php - 尝试从 AJAX 中的文本框获取值并将其发送到新页面

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

MySQL 错误 : Can't create/write to file '/var/mysqltmp/#sql_1fbd_0.MYI' (Errcode: 13)

mysql - wamp mysql 无法连接到本地主机

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

mysql - 如果是另一个查询的结果,则查询选择 Id

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