How to import an existing database into the estate?

I am learning to use Homestead 2.0. I have an existing MySQL database on my local machine. If I create a new laravel 5.0 project in a homestead virtual machine, what should I do to connect to an existing database?

  • If I need to transfer the database to Homestead, how to do it?
  • If I can connect to my database from Homestead, how can I configure it on Homestead?

Thanks.

+8
php mysql laravel-5 homestead
source share
2 answers

I had the same problem; this is how i resolve it

I was developing a laravel 4.2 project with WampServer as a development environment, later I decided to switch to laravel homestead as a development environment

Steps:

Save your database as a .sql file (my case: exported from phpMyAdmin and saved as db.sql)

Put the .sql file in the root of your project

Go to your farm directory

C:\Users\chebaby\Homestead (master) 

Enter the stray box

 vagrant ssh 

Go to the project root in the field (where you saved the early darabase.sql file in my case: db.sql)

 vagrant@homestead:~$ cd Code/project-folder/ 

Login to mysql

 vagrant@homestead:~/Code/project-folder$ mysql --user=homestead --password=secret 

to check if your database exists.

 mysql> show databases; 

Just create your database by running this command

 mysql> create database yourdatabasename; 

Now that you are sure that your database is created, exit mysql back to the abusive prompt

 mysql> exit; 

Imports a database file by running this

 vagrant@homestead:~/Code/project-folder$ mysql --user=homestead --password=secret yourdatabasename < db.sql 

All you have to do is check if your existing database has been imported successfully

Login to mysql

 vagrant@homestead:~/Code/project-folder$ mysql --user=homestead --password=secret 

then run

 mysql> use yourdatabasename 

To show running tables

 mysql> show tables; 

hope this answers your question

Additional resources

Laravel Homestead - default MySQL credentials and database

How to import SQL file using command line in MySQL?

+9
source share

Think of your Homestead installation as a remote host running on a completely different machine. Homestead does not know anything about your local host and therefore cannot directly connect to locally hosted MySQL databases.

Your Homestead installation works by its own IP address. Regardless of the IP address (probably 192.168.10.10), you can connect to it using MySQL Workbench or SequelPro using the following credentials:

Host: your IP address Homestead Port: 3306
Username: homestead Password: Secret

You can find your IP address by opening the following file:

~ / .homestead / Homestead.yaml

If you are on Windows, then it will probably be:

C: \ Users \ username \ .homestead \ Homestead.yaml

To interact with your database, make sure that Homestead is launched first by running vagrant up in your Homestead directory, otherwise it will fail.

After that, you can export your local database and import it back into one of your Homestead databases using the credentials described above.

+1
source share

All Articles