I'm starting a large project in Laravel 5. In the past I used XAMPP for all local work. Now we're going to work in Homestead. I got Homestead set up and running and I booted up a Laravel 5 project in it. works fine.
我正在Laravel 5开始一个大型项目。过去我使用XAMPP进行所有本地工作。现在我们将在Homestead工作。我让Homestead建立并运行,我启动了一个Laravel 5项目。工作正常。
Because of various reasons we do NOT want to use Laravel migrations but are using MYSQL workbench in combo with XAMPP-PHPMyAdmin for work on the mysql database. My question is: how can I access this mysql database from within the Homestead VM?
由于各种原因,我们不想使用Laravel迁移,而是使用MYSQL工作台与XAMPP-PHPMyAdmin组合来处理mysql数据库。我的问题是:如何从Homestead VM中访问这个mysql数据库?
I tried all kinds of settings in the app/Config/database.php. but none work.
我在app / Config / database.php中尝试了各种设置。但没有工作。
I looked around for related questions here, but none seem to answer the base of my question: is it even possible to access a remote database (or one on my host machine) from within homestead?
我在这里四处寻找相关问题,但似乎没有人回答我的问题:是否有可能从宅基地内访问远程数据库(或主机上的数据库)?
I read somewhere that I can create migrations from an SQL dump to duplicate the DB in homestead using a package (https://github.com/Xethron/migrations-generator). using this as a workaround, I could connect my Laravel app to my DB I have set up in XAMPP, generate the migrations, then connect back to the Homestead DB and finally run the migrations. I think this could work but I would prefer direct connection. any suggestions on how to connect to a database outside the Homestead VM would be welcome.
我在某处读到我可以使用程序包(https://github.com/Xethron/migrations-generator)从SQL转储创建迁移以复制hometead中的数据库。使用它作为一种解决方法,我可以将我的Laravel应用程序连接到我在XAMPP中设置的数据库,生成迁移,然后连接回Homestead数据库,最后运行迁移。我认为这可行,但我更喜欢直接连接。有关如何连接到Homestead VM之外的数据库的任何建议都将受到欢迎。
2 个解决方案
#1
1
I am also relatively new to Laravel and Homestead too but have had some luck with it.
我也是Laravel和Homestead的新手,但也有一些运气。
First I'm not sure it's such a great idea not to use the MySQL instance inside Homestead but if you have your reasons I'll take you at your word. That said from your "Homestead" directory you can "vagrant ssh" into your Homestead VM.
首先,我不确定在Homestead内部使用MySQL实例是一个好主意,但如果你有理由我会接受你的话。从您的“Homestead”目录中可以看出,您可以将“vagrant ssh”放入您的Homestead VM中。
Here you can mysql -u homestead -psecret dbname into your database and configure it at will just as you would your XAMPP instance. If you are using Laravel models as long as they match the database you'll be fine.
在这里你可以将mysql -u homestead -psecret dbname放入你的数据库并随意配置它就像你的XAMPP实例一样。如果您使用的是Laravel模型,只要它们与数据库匹配就可以了。
To your point of connecting to another database from within the VM have you tried to connect to that outside database from the command line? As long as your XAMPP MySQL instance is configured to receive remote connections and you have a user properly configured you should be able to test from the command line from within the Vagrant VM. See below where 192.168.1.196 is the IP address of the box/VM containing the MySQL instance to which you want to connect. I'm not running XAMPP but I was able to make a connection from within Vagrant Homestead out of the VM to another MySQL instance running on my local machine by providing my local network address. "127.0.0.1" won't work obviously because the Vagrant VM will perceive that as itself.
要从VM中连接到另一个数据库,您是否尝试从命令行连接到该外部数据库?只要您的XAMPP MySQL实例配置为接收远程连接并且您已正确配置用户,您就应该能够从Vagrant VM中的命令行进行测试。请参见下文,其中192.168.1.196是包含要连接的MySQL实例的框/ VM的IP地址。我没有运行XAMPP,但是我能够通过提供我的本地网络地址,从Vagrant Homestead中将VM连接到我本地计算机上运行的另一个MySQL实例。 “127.0.0.1”显然不会起作用,因为Vagrant VM会将其视为自身。
mysql -u user -ppassword dbname -h 192.168.1.196
Hope this helps.
希望这可以帮助。
#2
1
<1>Open .env (can be found in root of laravel)
<1>打开.env(可以在laravel的根目录中找到)
<2>Change DB_HOST to your LAN IP address(something like 198.168.0.11)
<2>将DB_HOST更改为您的LAN IP地址(类似于198.168.0.11)
DB_HOST=LAN_IP
<3>Now go to phpmyadmin and in privileges tab Add new user and fill login info
<3>现在转到phpmyadmin并在特权选项卡中添加新用户并填写登录信息
Select host as any_host(or fill host with your PC name)
选择host作为any_host(或使用您的PC名称填充主机)
#1
1
I am also relatively new to Laravel and Homestead too but have had some luck with it.
我也是Laravel和Homestead的新手,但也有一些运气。
First I'm not sure it's such a great idea not to use the MySQL instance inside Homestead but if you have your reasons I'll take you at your word. That said from your "Homestead" directory you can "vagrant ssh" into your Homestead VM.
首先,我不确定在Homestead内部使用MySQL实例是一个好主意,但如果你有理由我会接受你的话。从您的“Homestead”目录中可以看出,您可以将“vagrant ssh”放入您的Homestead VM中。
Here you can mysql -u homestead -psecret dbname into your database and configure it at will just as you would your XAMPP instance. If you are using Laravel models as long as they match the database you'll be fine.
在这里你可以将mysql -u homestead -psecret dbname放入你的数据库并随意配置它就像你的XAMPP实例一样。如果您使用的是Laravel模型,只要它们与数据库匹配就可以了。
To your point of connecting to another database from within the VM have you tried to connect to that outside database from the command line? As long as your XAMPP MySQL instance is configured to receive remote connections and you have a user properly configured you should be able to test from the command line from within the Vagrant VM. See below where 192.168.1.196 is the IP address of the box/VM containing the MySQL instance to which you want to connect. I'm not running XAMPP but I was able to make a connection from within Vagrant Homestead out of the VM to another MySQL instance running on my local machine by providing my local network address. "127.0.0.1" won't work obviously because the Vagrant VM will perceive that as itself.
要从VM中连接到另一个数据库,您是否尝试从命令行连接到该外部数据库?只要您的XAMPP MySQL实例配置为接收远程连接并且您已正确配置用户,您就应该能够从Vagrant VM中的命令行进行测试。请参见下文,其中192.168.1.196是包含要连接的MySQL实例的框/ VM的IP地址。我没有运行XAMPP,但是我能够通过提供我的本地网络地址,从Vagrant Homestead中将VM连接到我本地计算机上运行的另一个MySQL实例。 “127.0.0.1”显然不会起作用,因为Vagrant VM会将其视为自身。
mysql -u user -ppassword dbname -h 192.168.1.196
Hope this helps.
希望这可以帮助。
#2
1
<1>Open .env (can be found in root of laravel)
<1>打开.env(可以在laravel的根目录中找到)
<2>Change DB_HOST to your LAN IP address(something like 198.168.0.11)
<2>将DB_HOST更改为您的LAN IP地址(类似于198.168.0.11)
DB_HOST=LAN_IP
<3>Now go to phpmyadmin and in privileges tab Add new user and fill login info
<3>现在转到phpmyadmin并在特权选项卡中添加新用户并填写登录信息
Select host as any_host(or fill host with your PC name)
选择host作为any_host(或使用您的PC名称填充主机)