Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

php - Connecting to MySQL outside of Vagrant box

I tried to sudo netstat -natp | grep mysql to see what port mysql was listening on and I see that it is actually listening on what is below. I also did an ifconfig to see what ip I was on within the vagrant box. I am trying to find out this info so that I can connect to a mysql database through a vagrant virtual machine, but use that information in an .env inside of a laravel application that is outside of the box. Can anyone help?

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LIST

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In /etc/my.cnf, make ensure you have the following configuration:

1) Comment out this line if it's present, as it prevents external access

#skip-networking

2) Set bind-address to as follows, if set to locahost, only local connections will be possible:

bind-address=0.0.0.0

3) Restart MySQL with:

sudo service mysql restart

This should do it.

If it doesn't then you may have a firewall consideration to take care of. If you're on the default iptables, then run:

iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

To verify the port is open, from your external host (not the VM) you can run:

nmap <vm-ip-address-here> 

If you don't see 3306 open, you have other uncommon networking issues.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...