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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With