2016-07-28 84 views
2

我剛剛創建了一個新的laravel項目,我使用的是宅基地流浪漢盒通過運行家園 - 連接到我的數據庫

vagrant init laravel/homestead

Vagrant Up

當我使用vagrant ssh它給了我沒問題,我可以訪問流浪盒,但是當我想用Heidisql連接到數據庫時,出現連接錯誤:

can't connect to mysql server on 'localhost' (10061)

這裏是我的設置

enter image description here enter image description here

我使用的密碼= 「祕密」

回答

2

您應根據official documentation使用端口33060,而不是3306。

.env文件也應相應地更新,因此在運行第一次遷移時不會出現問題,因爲Laravel安裝在虛擬機內運行,您需要默認端口3306。

3

MySQL official documentation顯示

The error (2003) Can't connect to MySQL server on 'server' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, and that the network port you specified is the one configured on the server.

您試圖訪問一個MySQL服務器在另一臺機器,使用虛擬IP。我將使用我的IP,以便您更好地理解。

我的主機有2個IP:

  • 真正的IP是192.168.0.53
  • 虛擬IP是192.168.10.1

你可以看到你的主機IP在一個執行Windows機器

ipconfig 

and in a Unix machine

ifconfig 

您必須登錄到使用

vagrant ssh 

然後,你必須執行

ifconfig 

看到虛擬機的IP的無業遊民機。

在我流浪VM的IP是:

  • 10.0.2.15
  • 192.168.10.10

你可以看到,我有一個IP的主機(192.168.10.1)和一個在同一局域網內的Vagrant虛擬機(192.168.10.10)中。

Vagrant虛擬機IP(在我的例子中是192.168.10.10)是你必須在你的MySQL客戶端中使用的IP。