Friday, January 13, 2017

Host xxx.xxxx.xxxx.xxxx is not allowed to connect to this MySQL server?

Host xxx.xxxx.xxxx.xxxx is not allowed to connect to this MySQL server?

The answer to this question is quite good. Possibly a security precaution. Just try adding a new admin account.
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;
 
However I would not recommend you to grant all privileges to a non-root user.
 
You need to grant access to the user from any hostname and it can be done using 
phpmyadmin page.
This is how you add new privilege from phpmyadmin
Goto Privileges > Add a new User

Select Any Host for the desired username
For Ubuntu – if you are using ubuntu
Error message was similar and said 'Host XXX is not allowed to connect to this MySQL server' even though I was using root. Here's how to make sure that root has the correct permissions.
My setup:
  • Ubuntu 14.04 LTS
  • MySQL v5.5.37
Solution
  1. Open up the file under 'etc/mysql/my.cnf'
  2. Check for:
    • port (by default this is 'port = 3306')
    • bind-address (by default this is 'bind-address = 127.0.0.1'; if you want to open to all then just comment out this line. For my example, I'll say the actual server is on 10.1.1.7)
  3. Now access the MySQL Database on your actual server (say your remote address is 123.123.123.123 at port 3306 as user 'root' and I want to change permissions on database 'dataentry'. Remember to change the IP Address, Port, and database name to your settings)
    mysql -u root -p
    Enter password: <enter password>
    mysql>GRANT ALL ON *.* to root@'123.123.123.123' IDENTIFIED BY 'put-your-password';
    mysql>FLUSH PRIVILEGES;
    mysql>exit
  4. sudo service mysql restart
  5. You should now be able to remote connect to your database. For example, I'm using MySQL Workbench and putting in 'Hostname:10.1.1.7', 'Port:3306', 'Username:root'


No comments:

Post a Comment