【发布时间】:2016-06-08 03:51:00
【问题描述】:
我最近从使用内置的 Apache2 和 Mac 上的 PHP 安装切换到最新版本的 MAMP (3.5) 并将我的所有项目移到 htdocs 文件夹中。在我更新到新的 MySQL 信息后,除了我的 Laravel 项目外,一切正常。尝试访问使用 MySQL 的任何内容时,我收到此错误
PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'cumc'@'localhost' (using password: YES)
新的 .env 文件在数据库信息中如下所示。
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cumc
DB_USERNAME=root
DB_PASSWORD=root
因此,由于错误,似乎某些内容正在被缓存,但我已经运行了所有我能找到的缓存:清除命令,重新启动 MAMP,我的 Mac,并尝试了我能想到的一切。即使用新的详细信息更改app/database.php,并更改.env 的名称使其无法加载,它仍然会显示错误。
这是config/database.php 文件
<?php
return [
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
【问题讨论】:
-
尝试在 Config->database.php 以及 .env 文件中更改详细信息,然后使用此命令 php artisan serve
-
@PardeepPathania 是我能够让它工作的唯一方法是使用
php artisan serve?因为我希望 MAMP 允许我直接运行它而不必这样做。 -
1) 做一件事尝试创建虚拟主机。它可能会解决您的问题
-
@PardeepPathania 如何在 MAMP 中进行设置。我没有使用专业版。
标签: php mysql apache laravel mamp