21

I am trying to get MySQL server (which is inside VM) to respond to client (which is on the host machine). All methods return same:

Host '10.0.2.2' is not allowed to connect to this MySQL server

I have ensured proper port forwardind. I also ensured, that in my.cnf I have folowing lines:

skip-external-locking
bind-address = 0.0.0.0

This did not work to me. I also tried to play a bit as folowing:

bind-address = 10.0.2.2

But this also did not work to me - server just could not start.

Any ideas, where I am wrong?

UPDATE. I did not check privilegies for root@% as in How do I change the privileges for MySQL user that is already created?

SOLVED.

defance
  • 313
  • 1
  • 2
  • 8
  • What user accounts have you created within MySQL? – Shane Madden Mar 11 '13 at 16:21
  • My accout is `root:root`. I doubt that problem is in logins, otherwise error message would state something lile `Access denied for root@10.0.2.2` or something. – defance Mar 11 '13 at 16:23
  • @ShaneMadden Sorry. You were pretty right. The thing was in privilegies for `root@%`. Pretty my fault. – defance Mar 11 '13 at 16:30

1 Answers1

38

The root account's localhost-only in the vast majority of default installations, are you certain you've allowed it to log in from the other system? From the MySQL reference manual:

it means that there is no row in the user table with a Host value that matches the client host

So, there's no % or 10.0.2.2 in the Host column at all. Check your current config:

select user,host from mysql.user where user='root';

You likely want to create a new root entry with the same password as you have now.

create user 'root'@'10.0.2.2' identified by 'yourpassword';
grant all privileges on *.* to 'root'@'10.0.2.2' with grant option;
flush privileges;
Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • 1
    Yep. Thank you. I also solved it just a moment ago as you stated here. That was exact my problem. – defance Mar 11 '13 at 16:33
  • 1
    Shane's answer is correct and can be run in a single command, helpful if you are using something like an Ansible script/Vagrant to automate: `mysql -e "create user 'root'@'10.0.2.2' identified by 'yourpassword'; grant all privileges on *.* to 'root'@'10.0.2.2' with grant option; flush privileges;"` – KayakinKoder Aug 22 '16 at 19:11