不允许主机连接到此 MySQL 服务器以用于客户端 - 服务器应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28388914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:19:30  来源:igfitidea点击:

Host is not allowed to connect to this MySQL server for client-server application

mysql

提问by Kacy

I just exported my tables from one web host to another (AWS). Thinking everything would go smoothly (yeah right), well, everything that can go wrong has gone wrong.

我只是将我的表从一个网络主机导出到另一个 (AWS)。认为一切都会顺利(是的),好吧,一切可能出错的事情都出错了。

I get this error when trying to query my database (which I didn't get before):

尝试查询我的数据库时出现此错误(我以前没有遇到过):

SQLSTATE[HY000] [1130] Host '<my ip address>' is not allowed to connect to this MySQL server

SQLSTATE[HY000] [1130] Host '<my ip address>' is not allowed to connect to this MySQL server

This is the same error from this post:

这是这篇文章中的相同错误:

Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server

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

The solution in that post seems to revolve around having an administrative user. I am developing a chat application so every user needs to access the server (so I'm sure it's a bad idea to give them all administrative privileges). The answer by Pascal in that link says, If you are using mysql for a client/server application, prefer a subnet address.but I honestly don't understand what he means by that. And because of the amount of solutions, I'm not exactly sure which one I should follow based on my case.

那篇文章中的解决方案似乎围绕着拥有一个管理用户。我正在开发一个聊天应用程序,所以每个用户都需要访问服务器(所以我确信给他们所有的管理权限是一个坏主意)。帕斯卡在该链接中的回答说,If you are using mysql for a client/server application, prefer a subnet address.但老实说,我不明白他的意思。而且由于解决方案的数量,我不确定根据我的情况应该遵循哪一个。

How do I resolve this?

我该如何解决?

采纳答案by Charlie Martin

MySQL has security tables that determine who is allowed to connect and from what host IP address.

MySQL 具有安全表,用于确定允许谁连接以及从哪个主机 IP 地址进行连接。

Here's a good article on how to do it:

这是一篇关于如何做到这一点的好文章:

http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

If you have a lot of connections, consider setting up a server to accept the connections and talk to the sql server. The easiest approach to this is to set up a REST interface and use a web server. Web servers are usually also highly optimized and relatively bug free.

如果您有很多连接,请考虑设置一个服务器来接受连接并与 sql server 对话。最简单的方法是设置 REST 接口并使用 Web 服务器。Web 服务器通常也是高度优化的并且相对没有错误。

In a similar architecture on AWS, I use nginx happily.

在 AWS 上的类似架构中,我愉快地使用了 nginx。

回答by hd1

Make sure you have bind-address=YOUR-SERVER-IPin my.cnf and make sure you have a user [email protected]or hd1@%, the latter being a MySQL wildcard on the MySQL server. More information here. You may also need to grant access to port 3306 (the default MySQL port) on the security groups section of the AWS console.

确保您bind-address=YOUR-SERVER-IP在 my.cnf 中拥有并确保您有一个用户[email protected]or hd1@%,后者是 MySQL 服务器上的 MySQL 通配符。更多信息在这里。您可能还需要在 AWS 控制台的安全组部分授予对端口 3306(默认 MySQL 端口)的访问权限。

回答by Githiyon

// IN YOUR MYSQL WORKBENCH You Have to Execute below query

CREATE USER 'root'@'1.2.1.5(Your Application Server IP)' IDENTIFIED BY 'pass';

GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.200.1.54' WITH GRANT OPTION;

AFTER CREATING YOU CAN VIEW USING BELOW QUERY

SELECT * FROM mysql.user WHERE User = 'root';