Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Homestead - Connecting to my database

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

vagrant init laravel/homestead

and after

Vagrant Up

When I use vagrant ssh it 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:

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

Here's my setup

enter image description here enter image description here

the password I'm using = "secret"

like image 810
Nicolas Avatar asked Jul 28 '16 18:07

Nicolas


People also ask

How do I connect my homestead database?

Connecting To Your Databases To connect to your MySQL or Postgres database from your main machine via Navicat or Sequel Pro, you should connect to 127.0. 0.1 and port 33060 (MySQL) or 54320 (Postgres). The username and password for both databases is homestead / secret .

How do I connect to MySQL Homestead?

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.

How do I connect to homestead from the outside?

An alternate and more direct way to connect from the outside is to use the IP of your homestead environment. Unless you’ve changed it. It should be 192.168.10.10 by default but just to double check open up your Homestead.yaml. Here I’m using SQLYog to perform the connection using the following information

What port does homestead 7 use to connect to MySQL?

==> homestead-7: Forwarding ports... This makes the mysql port (3306) accessible from the outside environment using port (33060). This means you should technically be able to connect from the outside using port 33060 and using your local machine 127.0.0.1 as a host.

What credentials/info do I need to set up a homestead server?

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

What is the IP address of the homestead server?

IP address 192.168.10.10 (Check your Homestead Folder>Homestead.yaml) Port: 3306 User: homestead (all lowercase) Pw: secret Share Follow edited Jul 5 '19 at 19:52 mattwith 4344 bronze badges answered Aug 20 '18 at 21:01 DamiDami 52744 silver badges1212 bronze badges 1


5 Answers

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
like image 180
Dami Avatar answered Oct 21 '22 10:10

Dami


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.

like image 32
Cristian F. Avatar answered Oct 21 '22 08:10

Cristian F.


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

like image 40
Ezequiel Alanis Avatar answered Oct 21 '22 10:10

Ezequiel Alanis


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.

like image 44
Jesús Amieiro Avatar answered Oct 21 '22 10:10

Jesús Amieiro


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.

like image 2
Dusan Jovanov Avatar answered Oct 21 '22 08:10

Dusan Jovanov