简体   繁体   English

Laravel Homestead无法从主机连接到MySQL

[英]Laravel Homestead Failed to Connect to MySQL from the host machine

Since I installed Laravel Homestead (via Vagrant) I'm not able to connect to MySql from my host machine (Windows). 由于我安装了Laravel Homestead (通过Vagrant),因此无法从主机 (Windows)连接到MySql。 However, I can connect to the MySql server from the VM itself without any problem (ie from the homestead Virtual Machine). 但是,我可以从VM本身连接到MySql服务器,而没有任何问题(例如,从宅基地虚拟机)。

I'll explain the steps I took while trying to solve this issue and will paste parts of my configuration files with the hope you'll figure it out. 我将解释在尝试解决此问题时所采取的步骤,并粘贴部分配置文件,希望您能弄清楚。

While trying to connect from a remote (ie my host machine) I'm getting the following error message both in MySQL Workbench and on MySQL Client: 尝试从远程(即我的主机)连接时,在MySQL Workbench和MySQL Client上都收到以下错误消息:

Lost connection to MySQL server at 'reading authorization packet', system error: 2 在“读取授权包”时与MySQL服务器的连接断开,系统错误:2

I dug the Internet for a week and found nothing that can solve my problem. 我在互联网上挖了一个星期,发现没有什么可以解决我的问题的。 Here are some things I tried: 这是我尝试过的一些方法:

On my windows machine: 在我的Windows机器上:

  • Windows Firewall: Windows防火墙:
    • Allowed outbound and inbound traffic to and from Workbench on ports 3306 and 33060 在端口3306和33060上允许进出Workbench的出站和入站流量
    • Allow outbound traffic to 33060 允许出站流量达到33060

On Vagrant's Homestead machine (Ubuntu): 在Vagrant的Homestead机器(Ubuntu)上:

  • Edited /etc/hosts.allow to: /etc/hosts.allow编辑为:

     mysqld: 127.0.0.1 mysqld: ALL: allow 
  • Verified that /etc/hosts.deny isn't blocking any address 验证/etc/hosts.deny没有阻止任何地址

  • Added the following to /etc/mysql/mysql.conf.d/mysqld.cnf and /etc/mysql/my.cnf /etc/mysql/mysql.conf.d/mysqld.cnf/etc/mysql/my.cnf添加以下内容

     [mysqld] skip-name-resolve 

And more things similar and different to the mentioned above. 还有更多与上述相似和不同的东西。


This is how I tried to connect from the host-machine: 这是我尝试从主机连接的方式:

$ mysql -h 127.0.0.1 -P 33060 -u homestead

And these are screenshots from the failed attempts of MySQL Workbench (Click to enlarge): 这些是MySQL Workbench失败尝试的屏幕截图(单击放大):

在此处输入图片说明 在此处输入图片说明


Since it's highly important, here are my Vagrant and Homestead configuration files: 由于它非常重要,因此这里是我的Vagrant和Homestead配置文件:

Homestead.yaml Homestead.yaml

ip: "192.168.10.10"
...
<truncated>
...
databases:
    - homestead

The project's .env file: 项目的.env文件:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:<truncated>
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=homestead
DB_PASSWORD=secret  

As I said before, I'll try all of the above with different variations and shapes and came with the same issue again and again. 正如我之前说过的,我将尝试所有具有不同变体和形状的上述内容,并一次又一次地遇到相同的问题。 I also tried to play around with 127.0.0.1 and 192.168.10.10 with the thought that it might help but again, nope. 我还尝试使用127.0.0.1和192.168.10.10,以为这可能会有所帮助,但还是不行。 Will appreciate your help and will happily add any information that is needed 感谢您的帮助,并乐意添加所需的任何信息

I had the same issue but after running the mysql client as same admin as vagrant it work for me. 我有同样的问题,但是在以无业游民身份以相同的管理员身份运行mysql客户端后,它对我有用。 Try running it same user as vagrant first time. 第一次尝试以无业游民的身份运行该用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM