Laravel 4.2:(用户 'homestead'@'localhost' 的访问被拒绝)错误
Laravel 4.2: (Access denied for user 'homestead'@'localhost') error
当我尝试执行 php artisan migrate
命令时,我在终端中收到以下错误消息
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)
我不使用 homestead
。我在根目录中有这 2 个文件:.env.php
和 .env.local.php
,其中我保留了敏感值和环境(开发和生产)之间不同的值。那么问题出在哪里以及如何解决问题?
- 在您的终端中键入
hostname
,然后按 Enter 键。这会让您知道您的主机名(computer/machine 的名称)。
- 在
bootstrap/start.php
文件中,使用这一行 'local' => array('put-your-hostname-here'),
而不是这一行 'local' => array('homestead'),
在 .env.local.php
文件中,像这样保存本地数据库配置:
<?php
return array(
"DB_NAME" => "local_database_name",
"DB_USERNAME" => "local_database_username",
"DB_PASSWORD" => "local_database_password",
// any other configuration..
);
在 .env.php
文件中,像这样保存您的远程数据库配置:
<?php
return array(
"DB_NAME" => "remote_database_name",
"DB_USERNAME" => "remote_database_username",
"DB_PASSWORD" => "remote_database_password",
// any other configuration..
);
在 app/config/database.php
文件中,像这样设置数据库连接:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
最后,您必须删除或禁用 [=20=] 文件中存在的任何工作代码,否则将抛出您提到的错误。
当我尝试执行 php artisan migrate
命令时,我在终端中收到以下错误消息
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)
我不使用 homestead
。我在根目录中有这 2 个文件:.env.php
和 .env.local.php
,其中我保留了敏感值和环境(开发和生产)之间不同的值。那么问题出在哪里以及如何解决问题?
- 在您的终端中键入
hostname
,然后按 Enter 键。这会让您知道您的主机名(computer/machine 的名称)。 - 在
bootstrap/start.php
文件中,使用这一行'local' => array('put-your-hostname-here'),
而不是这一行'local' => array('homestead'),
在
.env.local.php
文件中,像这样保存本地数据库配置:<?php return array( "DB_NAME" => "local_database_name", "DB_USERNAME" => "local_database_username", "DB_PASSWORD" => "local_database_password", // any other configuration.. );
在
.env.php
文件中,像这样保存您的远程数据库配置:<?php return array( "DB_NAME" => "remote_database_name", "DB_USERNAME" => "remote_database_username", "DB_PASSWORD" => "remote_database_password", // any other configuration.. );
在
app/config/database.php
文件中,像这样设置数据库连接:'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => $_ENV['DB_NAME'], 'username' => $_ENV['DB_USERNAME'], 'password' => $_ENV['DB_PASSWORD'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ),
最后,您必须删除或禁用 [=20=] 文件中存在的任何工作代码,否则将抛出您提到的错误。