laravel 配置 Homestead 以使用 MySQL Workbench

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29679423/
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 11:22:03  来源:igfitidea点击:

Configuring Homestead to work with MySQL Workbench

laravelmysql-workbenchhomestead

提问by user3718908

I just started using Homestead today and so far I don't think I know what I am doing, previously I was using the inbuilt PHP server that comes with Laravel and I had MySQL server and workbench installed separately on my computer.

我今天刚开始使用 Homestead,到目前为止我不知道我在做什么,以前我使用 Laravel 附带的内置 PHP 服务器,并且我的计算机上分别安装了 MySQL 服务器和工作台。

With this setup I was able to connect to my database with ease, however since I got my Homestead running I can't seem to access that database again. This error keeps popping up:

通过这种设置,我可以轻松连接到我的数据库,但是自从我的 Homestead 运行后,我似乎无法再次访问该数据库。这个错误不断弹出:

3/3 ErrorException in Connector.php line 47: SQLSTATE[HY000] [1045] 
Access denied for user 'myproject_db101'@'localhost' (using password: YES) 
(View: /home/vagrant/Projects/myproject/resources/views/layout/index.blade.php) 
(View: /home/vagrant/Projects/myproject/resources/views/layout/index.blade.php) 

How can I fix this?

我怎样才能解决这个问题?

回答by Prakhar

I was facing the same issue and I tried below steps to fix it. Please let me know if they work for you.

我遇到了同样的问题,我尝试了以下步骤来解决它。请让我知道他们是否为您工作。

  1. Note the homestead ip address for your vagrant box. It is available in Homestead.yaml file under ~/.homestead directory. This directory location would be different on different OS. But since you have already installed vagrant with homestead you should know its location. For me the ip address was 192.168.10.10.
  2. Open up the Mysql Connection wizard and provide the below settings hostname = 192.168.10.10 port = 3306 username = homestead password = secret
  3. Test Your connection
  1. 记下你的 vagrant box 的 homestead ip 地址。它在 ~/.homestead 目录下的 Homestead.yaml 文件中可用。此目录位置在不同的操作系统上会有所不同。但是既然你已经在 homestead 上安装了 vagrant,你应该知道它的位置。对我来说,IP 地址是 192.168.10.10。
  2. 打开 Mysql 连接向导并提供以下设置 hostname = 192.168.10.10 port = 3306 username = homestead password = secret
  3. 测试您的连接

For me these settings worked. Check if they work for you.

对我来说,这些设置有效。检查它们是否适合你。

回答by Drew Hammond

Try using homestead's default MySQL credentials: User: rootPassword: secret

尝试使用 homestead 的默认 MySQL 凭据:用户:root密码:secret

If you are accessing the database from your computer via MySQL Workbench (not from within the homestead VM), you can use localhost:33060(note: non-standard port). This is mapped to port 3306 within your VM.

如果您通过 MySQL Workbench 从您的计算机访问数据库(而不是从 homestead VM 内),您可以使用localhost:33060(注意:非标准端口)。这映射到您的 VM 中的端口 3306。

From your application and any time you're working from within the homestead VM, you can connect to the database normally as localhost on port 3306.

在您的应用程序中以及任何时候您在 Homestead VM 中工作时,您都可以在端口 3306 上以 localhost 身份正常连接到数据库。

回答by Mike Lischke

Very likely a configuration issue. Either the user 'myproject_db101'@'localhost'has no password set or is not allowed to connect from localhost. You need another user with proper rights (e.g. the root user) to fix permissions for that user.

很可能是配置问题。用户'myproject_db101'@'localhost'没有设置密码或不允许从本地主机连接。您需要另一个具有适当权限的用户(例如 root 用户)来修复该用户的权限。

回答by Benjamin Bj?rn Nielsen

These other answers might have worked for you guys, but in case anyone has a case like mine, I'm just going to provide what worked for me. Hopefully it helps someone out. I'm working on a brand new homestead installation as of today, but on a very old mac in case thats relevant.

这些其他答案可能对你们有用,但如果有人有像我这样的情况,我只会提供对我有用的方法。希望它可以帮助某人。截至今天,我正在安装全新的宅基地,但在非常旧的 mac 上以防万一。

What worked for me was using the regular localhost ip of my machine as the host, and then the homested/secret combination for the password, and using the default port but with a 0 at the end. This adds up to be the following settings:

对我有用的是使用我机器的常规 localhost ip 作为主机,然后使用 hometed/secret 组合作为密码,并使用默认端口但最后是 0。这加起来就是以下设置:

Connection method: Standard (TCP/IP)

连接方式:标准(TCP/IP)

Host: 127.0.0.1
Username: homestead
Password: secret
Port: 33060

主机:127.0.0.1
用户名:homestead
密码:secret
端口:33060

Hopefully this helps someone out. Its the only configuration that worked for me.

希望这可以帮助某人。它是唯一对我有用的配置。