Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to Mysql Server inside VirtualBox Vagrant?

I mounted a new VirtualBox Machine with Vagrant, and inside that VM I installed Mysql Server. How can I connect to that server outside the vm? I already forward the port 3306 of the Vagrantfile , but when I try to connect to the mysql server, it`s resposts with the error: 'reading initial communication packet'

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
like image 714
rizidoro Avatar asked May 22 '12 20:05

rizidoro


2 Answers

Make sure MySQL binds to 0.0.0.0 and not 127.0.0.1 or it will not be accessible from outside the machine

You can ensure this by editing the /etc/mysql/my.conf file and looking for the bind-address item--you want it to look like bind-address = 0.0.0.0. Then save this and restart MySQL:

sudo service mysql restart

If you are doing this on a production server, you want to be aware of the security implications, discussed here: https://serverfault.com/questions/257513/how-bad-is-setting-mysqls-bind-address-to-0-0-0-0

like image 99
Dror Bereznitsky Avatar answered Nov 07 '22 04:11

Dror Bereznitsky


Log in to your box with ssh [email protected] -p 2222 (password vagrant)

Then: sudo nano /etc/mysql/my.cnf and comment out the following lines with #

#skip-external-locking 
#bind-address

save it & exit

then: sudo service mysql restart

Then you can connect through SSH to your MySQL server.

like image 49
Youri van den Bogert Avatar answered Nov 07 '22 05:11

Youri van den Bogert