在 Vagrant 框外连接到 MySQL [英] Connecting to MySQL outside of Vagrant box

查看:65
本文介绍了在 Vagrant 框外连接到 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图sudo netstat -natp |grep mysql 以查看 mysql 正在侦听的端口,我看到它实际上正在侦听下面的内容.我还做了一个 ifconfig 来查看我在 vagrant 框中使用的 ip.我试图找出此信息,以便我可以通过 vagrant 虚拟机连接到 mysql 数据库,但在开箱即用的 laravel 应用程序内的 .env 中使用该信息.有人可以帮忙吗?

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

推荐答案

在/etc/my.cnf中,确保你有以下配置:

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

1) 注释掉这一行(如果它存在),因为它会阻止外部访问

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

#skip-networking

2) 如下设置bind-address,如果设置为locahost,则只能本地连接:

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

bind-address=0.0.0.0

3) 使用以下命令重启 MySQL:

3) Restart MySQL with:

sudo service mysql restart

应该这样做.

如果没有,那么您可能需要考虑防火墙.如果您使用的是默认的 iptables,请运行:

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

要验证端口是否打开,您可以从外部主机(而不是 VM)运行:

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

nmap <vm-ip-address-here> 

如果您没有看到 3306 打开,则您有其他不常见的网络问题.

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

这篇关于在 Vagrant 框外连接到 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆