简体   繁体   中英

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). However, I can connect to the MySql server from the VM itself without any problem (ie from the homestead Virtual Machine).

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:

Lost connection to MySQL server at 'reading authorization packet', system error: 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 Firewall:
    • Allowed outbound and inbound traffic to and from Workbench on ports 3306 and 33060
    • Allow outbound traffic to 33060

On Vagrant's Homestead machine (Ubuntu):

  • Edited /etc/hosts.allow to:

     mysqld: 127.0.0.1 mysqld: ALL: allow 
  • Verified that /etc/hosts.deny isn't blocking any address

  • Added the following to /etc/mysql/mysql.conf.d/mysqld.cnf and /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):

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


Since it's highly important, here are my Vagrant and Homestead configuration files:

Homestead.yaml

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

The project's .env file:

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. 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. Try running it same user as vagrant first time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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