Homestead - Connecting to my database

前端 未结 6 1727
渐次进展
渐次进展 2021-01-17 23:52

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

vagrant init laravel/homestead

and aft

相关标签:
6条回答
  • 2021-01-18 00:14

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

    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.

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

    0 讨论(0)
  • 2021-01-18 00:23

    First tab (Instelligen):

    • IP Address: the IP that you defined in the Homestead.yaml file (mine is: 192.168.10.10)
    • Username: homestead
    • Password: secret

    Second tab (SSH):

    • IP Address - same as on the first tab
    • Username: vagrant
    • Password: vagrant

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

    0 讨论(0)
  • 2021-01-18 00:28

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

    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.

    0 讨论(0)
  • 2021-01-18 00:33

    The MySQL official documentation shows

    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.

    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.

    My host machine has 2 IP:

    • the real IP is 192.168.0.53
    • the virtual IP is 192.168.10.1

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

    ipconfig 
    

    and in a Unix machine

    ifconfig 
    

    You have to login to the Vagrant machine using

    vagrant ssh
    

    Then you have to execute

    ifconfig
    

    to see the IP's of the virtual machine.

    In my Vagrant VM the IP are:

    • 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.

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

    0 讨论(0)
  • 2021-01-18 00:35

    [Official Doc][1]

    [1]: https://laravel.com/docs/5.8/homestead#connecting-to-databases is instructed to use port 33060 for MySQL and 54320 for PostgreSQL

    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 on port 33060 (MySQL) or 54320 (PostgreSQL). The username and password for both databases is homestead / secret.

    0 讨论(0)
  • 2021-01-18 00:40

    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
    0 讨论(0)
提交回复
热议问题