laravel Homestead - 连接到我的数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38643837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:13:37  来源:igfitidea点击:

Homestead - Connecting to my database

mysqllaravelhomestead

提问by Nicolas

I just created a fresh laravel project and I'm using a Homestead vagrant box by running

我刚刚创建了一个新的 Laravel 项目,我正在通过运行使用 Homestead vagrant box

vagrant init laravel/homestead

vagrant init laravel/宅基地

and after

之后

Vagrant Up

流浪

When I use vagrant sshit gives me no problem and I can acces the vagrant box, however when I want to connect to the DB with Heidisql I get a connection error:

当我使用vagrant ssh它时没有问题,我可以访问 vagrant box,但是当我想使用 Heidisql 连接到数据库时,出现连接错误:

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

无法连接到 'localhost' (10061) 上的 mysql 服务器

Here's my setup

这是我的设置

enter image description hereenter image description here

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

the password I'm using = "secret"

我使用的密码 = "secret"

回答by Cristian F.

You should be using the port 33060 instead of 3306 according to the official documentation.

根据官方文档,您应该使用端口 33060 而不是 3306 。

The .env file should also be updated accordingly, so you won't have issues when running your first migration, as the Laravel installation is running inside the virtual machine you need the default port 3306 there.

.env 文件也应该相应地更新,所以你在第一次迁移时不会有问题,因为 Laravel 安装在虚拟机内运行,你需要那里的默认端口 3306。

回答by Dami

The usual credentials/info you need:

您需要的常用凭据/信息:

  • IP address 192.168.10.10 (Check your Homestead Folder>Homestead.yaml)
  • Port: 3306
  • User: homestead (all lowercase)
  • Pw: secret
  • IP 地址 192.168.10.10(检查您的 Homestead 文件夹>Homestead.yaml)
  • 端口:3306
  • 用户:宅基地(全部小写)
  • 密码:秘密

回答by Jesús Amieiro

The MySQL official documentationshows

MySQL的官方文档显示

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.

错误 (2003) Can't connect to MySQL server on 'server' (10061) 表示网络连接已被拒绝。您应该检查是否有 MySQL 服务器在运行,是否启用了网络连接,以及您指定的网络端口是否是服务器上配置的端口。

You are trying to access to a MySQL server in another machine, with a virtual IP. I will use my IP's so you can understand better.

您正在尝试使用虚拟 IP 访问另一台机器上的 MySQL 服务器。我将使用我的 IP,以便您更好地理解。

My host machine has 2 IP:

我的主机有 2 个 IP:

  • the real IP is 192.168.0.53
  • the virtual IP is 192.168.10.1
  • 真实IP是192.168.0.53
  • 虚拟 IP 是 192.168.10.1

You can see your host machine IP's executing in a Windows machine

你可以看到你的主机 IP 在 Windows 机器上执行

ipconfig 

and in a Unix machine

并且在一台 Unix 机器上

ifconfig 

You have to login to the Vagrant machine using

您必须使用登录到 Vagrant 机器

vagrant ssh

Then you have to execute

然后你必须执行

ifconfig

to see the IP's of the virtual machine.

查看虚拟机的IP。

In my Vagrant VM the IP are:

在我的 Vagrant VM 中,IP 是:

  • 10.0.2.15
  • 192.168.10.10
  • 10.0.2.15
  • 192.168.10.10

You can see that I have one IP in the host machine (192.168.10.1) and one in the Vagrant VM (192.168.10.10) in the same LAN.

你可以看到我在同一局域网中的主机(192.168.10.1)和 Vagrant VM(192.168.10.10)中有一个 IP。

The Vagrant VM IP (192.168.10.10 in my example) is the one you have to use in your MySQL client.

Vagrant VM IP(在我的示例中为 192.168.10.10)是您必须在 MySQL 客户端中使用的 IP。

回答by Ezequiel Alanís

The Homestead documentation says that you should use address 127.0.0.1 port 33060 to connect. I made a test and it worked.

Homestead 文档说你应该使用地址 127.0.0.1 端口 33060 来连接。我做了一个测试,它奏效了。

A homestead database is configured for both MySQL and PostgreSQL out of the box. To connect to your MySQL or PostgreSQL database from your host machine's database client, you should connect to 127.0.0.1 and port 33060 (MySQL) or 54320 (PostgreSQL). The username and password for both databases is homestead / secret.

为 MySQL 和 PostgreSQL 配置了一个开箱即用的 homestead 数据库。要从主机的数据库客户端连接到 MySQL 或 PostgreSQL 数据库,您应该连接到 127.0.0.1 和端口 33060 (MySQL) 或 54320 (PostgreSQL)。两个数据库的用户名和密码都是 homestead / secret。

Source: https://laravel.com/docs/5.8/homestead#configuring-homestead

来源:https: //laravel.com/docs/5.8/homestead#configuring-homestead

回答by Dusan Jovanov

First tab (Instelligen):

第一个选项卡(智能):

  • IP Address: the IP that you defined in the Homestead.yamlfile (mine is: 192.168.10.10)
  • Username: homestead
  • Password: secret
  • IP 地址:您在Homestead.yaml文件中定义的 IP (我的是:192.168.10.10)
  • 用户名:宅基地
  • 密码:秘密

Second tab (SSH):

第二个选项卡 (SSH):

  • IP Address - same as on the first tab
  • Username: vagrant
  • Password: vagrant
  • IP 地址 - 与第一个选项卡上的相同
  • 用户名:流浪
  • 密码:流浪

Leave everything else the same. This worked for me. I'm using the same HeidiSQL program.

保持其他一切不变。这对我有用。我正在使用相同的 HeidiSQL 程序。