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

我与影子孤独终老i 提交于 2021-02-10 09:32:17

问题


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.

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

This is the same error from this post:

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

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.

How do I resolve this?


回答1:


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

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

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.

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




回答2:


Make sure you have bind-address=YOUR-SERVER-IP in my.cnf and make sure you have a user hd1@172.31.39.86 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.




回答3:


// 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';


来源:https://stackoverflow.com/questions/28388914/host-is-not-allowed-to-connect-to-this-mysql-server-for-client-server-applicatio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!