Laravel Homestead 无法连接到数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24095563/
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
Laravel Homestead can't connect to db
提问by murum
I'm having trouble connecting to the database when using Laravel Homestead. I can't really understand why it doesn't work I've tried god damn everything I guess. Now i got stuck and can't try much more and I start to interact with more people. Does stackoverflow have any good answer or advice to give me? :)
我在使用 Laravel Homestead 时无法连接到数据库。我真的不明白为什么它不起作用我已经尝试了我猜的该死的一切。现在我被卡住了,不能尝试更多,我开始与更多的人互动。stackoverflow 有什么好的答案或建议可以给我吗?:)
This is my settings
这是我的设置
'mysql' => array(
'driver' => 'mysql',
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'port' => '33060'
)
I've also tried this with the same response.
我也用同样的回应尝试过这个。
'mysql' => array(
'driver' => 'mysql',
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'port' => '3306'
)
This is my ENV variables.
这是我的 ENV 变量。
{
host: "127.0.0.1",
database: "homestead",
username: "homestead",
password: "secret"
}
The return is:
回报是:
PDOException
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)
In both Migrations as the website.
在作为网站的两个迁移中。
It works to connect with Sequel Pro, it looks like this in Sequel Pro.
它可以与 Sequel Pro 连接,在 Sequel Pro 中看起来像这样。
EDIT:Is it possible that there's some kinda collision between my VagrantBox's IP and the MAMP one? I've stopped every MAMP thing I've running but still the same issue, just wondering if I need to stop it somewhere else?
编辑:我的 VagrantBox 的 IP 和 MAMP 的 IP 之间是否可能存在某种冲突?我已经停止了我正在运行的所有 MAMP 东西,但仍然是同样的问题,只是想知道我是否需要在其他地方停止它?
回答by Joel Hinz
You shouldn't need to specify the port at all, I'd remove that line. For host, try localhost
instead. Also make sure that Homestead uses the environment you have set your database to, most likely local
.
您根本不需要指定端口,我会删除该行。对于主机,请尝试localhost
。还要确保 Homestead 使用您为数据库设置的环境,很可能local
。
MAMP can't conflict with it, unless you've at some point manually set your MAMP MySQL port to 33060, which I very much doubt.
MAMP 不能与之冲突,除非您在某个时候手动将 MAMP MySQL 端口设置为 33060,我对此非常怀疑。
Here's a default file which works great for me:
这是一个对我很有用的默认文件:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'mydbname',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Lycka till!
Lycka直到!
回答by Antoine Augusti
What have you got when you open the PHP REPL by typing php artisan tinker
at the root of your project and then print_r(Config::get('database.connections')['mysql']);
?
当您通过php artisan tinker
在项目的根目录下键入然后打开 PHP REPL 时,您得到了什么print_r(Config::get('database.connections')['mysql']);
?
You should have this:
你应该有这个:
Array
(
[driver] => mysql
[host] => localhost
[database] => homestead
[username] => homestead
[password] => secret
[charset] => utf8
[collation] => utf8_unicode_ci
[prefix] =>
[port] => 33060
)
If you have something different your environment variables are not good or you are not detecting the local environment.
如果你有不同的东西,你的环境变量不好,或者你没有检测到本地环境。