Monday, April 27, 2015

Connection Failed: 'host' is not allowed to connect to this mysql server

Hello,

If you are getting following error while trying to connect your (PHP) application to a MySQL database

Connection Failed: 'host' is not allowed to connect to this MySQL server

Then this may due to limited privileges given to the user through which one s trying to connect with the server. Although a correct username and password is been used to connect still we have this error.

What happens is when a new MySQL user is added to a DB then the hostname name like localhost is added by default to user like user1@localhost. Now this user can access the DB for sure but while he is on the same machine not remotely.

The solution for this issue is to create a new user which has Any Host privileges "%" like

mysql> CREATE USER 'user2'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user2'@'%' -> WITH GRANT OPTION;


Thanx
Anshumaan Bakshi