MySQL Error 2003 – 10061 – Connecting to a Virtual Machine

If you are trying to connect to your MySQL instance on a virtual machine (VirtualBox / Ubuntu) and you are getting the following error :


ERROR 2003 (HY000): Can't connect to MySQL server on 'xx.xx.xx.xx' (10061)

There are two tiny little configurations that you might be missing:

1 – User’s Permissions to access MySQL from the host machine

 

By default all the users in MySQL are considered to be connecting from the local machine, not any remote host. So you should add a new user or giving the privileges to an existing user to be able to connect from your host machine or anywhere else. Here is how to do it:


GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'host_name' IDENTIFIED BY 'new_password';

You could replace “host_name” by the real machine’s name or “%” to make it accessible by any host ( watch out for the security flaws if you going for a wildcard access)

2 – MySQL configuration

 

In the my.cnf file, you should specify for MySQL which IP address to bind to. So you can open up the my.cnf ( which in my case is located in : /etc/mysql/my.cnf) and edit the following line :

bind-address = 10.xxx.xx.xx

And this is the IP address of the Guest OS.

P.S.: This is with the assumption that the Network Adapter in the Virtual Machine is set to Bridged, so the host and guest OS are having separate IP addresses.

Hope it helps.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s