PDOException(1045)SQLSTATE Laravel 4.2 MySQL 5.7

感谢您阅读我的问题,自从在ServerFault,Stackoverflow和AskUbuntu上阅读问题一周以来,我一直在处理这个错误,但无法找出问题所在。

我有

  • Lubuntu 16.04(ubuntu发行版)
  • Nginx的
  • Laravel 4.2.17
  • MySQL 5.7

我有一个预先存在的项目,我从GitHub克隆,一切都很顺利,但当我去一个页面,必须连接到数据库(如尝试login)我得到这个错误:

PDOException(1045)HELP

SQLSTATE [HY000] [1045]拒绝用户'宅地'@'localhost'的访问(使用密码:是)

graphics描述的错误

文件涉及

我有一个.env文件在项目中,我已经命名为.env.local.php这是文件:

<?php /** * Variables de entorno .env.php * Si se requiere cargar otros valores para un entorno diferente al de produccion (local, development, etc.) * cree un archivo con el nombre asi: * - local => .env.local.php * - development => .env.development.php */ return [ 'DATABASE_NAME' => 'DATABASE_NAME', 'DATABASE_USER' => 'DATABASE_USER', 'DATABASE_PASSWORD' => 'DATABASE_PASSWORD', /* * social * '$RED$_IDENTIFIER' => '', * '$RED$_SECRET' => '', * '$RED$_CALLBACK_URI' => '', */ 'GOOGLE_IDENTIFIER' => 'GOOGLE_IDENTIFIER', 'GOOGLE_SECRET' => 'GOOGLE_SECRET', 'GOOGLE_CALLBACK_URI' => 'GOOGLE_CALLBACK_URI', 'FACEBOOK_IDENTIFIER' => 'FACEBOOK_IDENTIFIER', 'FACEBOOK_SECRET' => 'FACEBOOK_SECRET', 'FACEBOOK_CALLBACK_URI' => 'FACEBOOK_CALLBACK_URI', /** * PayU configs * PAYU_TEST: 1 = Modo prueba, 0 = Modo Produccion */ 'PAYU_MACRO_ACCOUNT_ID' => 654321, 'PAYU_MICRO_ACCOUNT_ID' => 123456, 'PAYU_MERCHANT_ID' => 123456, 'PAYU_API_KEY' => 'ABCabc123DEFdef456GHIghi78', 'PAYU_API_LOGIN' => '123abc456def789', 'PAYU_TEST' => 1, ]; 

我在/var/www/kinbuweb/app/config/local/database.php中有一个database.php文件,我突出显示/ config /本地path,我一直在阅读的是configuration,如果我有一个本地环境(和我已经命名我的文件.env。 本地 .php)path中的文件:

 <?php return [ /* |-------------------------------------------------------------------------- | 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' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'homestead', 'username' => 'homestead', 'password' => 'secret', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ], 'pgsql' => [ 'driver' => 'pgsql', 'host' => 'localhost', 'database' => 'homestead', 'username' => 'homestead', 'password' => 'secret', 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', ], ], ]; 

另一方面,我有一个文件出了本地文件夹(path:/ var / www / kinbuweb /应用程序/configuration)这也被称为database.php ,我认为是它的一般configuration:

 <?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' => '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' => __DIR__ . '/../database/production.sqlite', 'prefix' => '', ], 'mysql' => [ 'driver' => 'mysql', 'host' => 'localhost', 'database' => $_ENV['DATABASE_NAME'], 'username' => $_ENV['DATABASE_USER'], 'password' => $_ENV['DATABASE_PASSWORD'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ], 'pgsql' => [ 'driver' => 'pgsql', 'host' => 'localhost', 'database' => 'forge', 'username' => 'forge', 'password' => '', 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', ], 'sqlsrv' => [ 'driver' => 'sqlsrv', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'prefix' => '', ], ], /* |-------------------------------------------------------------------------- | 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 a typical key-value systems | such as APC or Memcached. Laravel makes it easy to dig right in. | */ 'redis' => [ 'cluster' => false, 'default' => [ 'host' => '127.0.0.1', 'port' => 6379, 'database' => 0, ], ], ]; 

我曾经试过

  1. 使用本地(/var/www/kinbuweb/app/config/local/database.php)database.phpconfiguration中的凭据,如下所示:

     <?php /** * Variables de entorno .env.php * Si se requiere cargar otros valores para un entorno diferente al de produccion (local, development, etc.) * cree un archivo con el nombre asi: * - local => .env.local.php * - development => .env.development.php */ return [ 'DATABASE_NAME' => 'homestead', 'DATABASE_USER' => 'homestead', 'DATABASE_PASSWORD' => 'secret', 'GOOGLE_IDENTIFIER' => 'GOOGLE_IDENTIFIER', 'GOOGLE_SECRET' => 'GOOGLE_SECRET', 'GOOGLE_CALLBACK_URI' => 'GOOGLE_CALLBACK_URI', 'FACEBOOK_IDENTIFIER' => 'FACEBOOK_IDENTIFIER', 'FACEBOOK_SECRET' => 'FACEBOOK_SECRET', 'FACEBOOK_CALLBACK_URI' => 'FACEBOOK_CALLBACK_URI', 'PAYU_MACRO_ACCOUNT_ID' => 654321, 'PAYU_MICRO_ACCOUNT_ID' => 123456, 'PAYU_MERCHANT_ID' => 123456, 'PAYU_API_KEY' => 'ABCabc123DEFdef456GHIghi78', 'PAYU_API_LOGIN' => '123abc456def789', 'PAYU_TEST' => 1, ]; 
  2. 将端口聚合到本地文件夹中的数据库configuration,如下所示:

     <?php return [ 'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => 'localhost:3306', 'database' => 'homestead', 'username' => 'homestead', 'password' => 'secret', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ], 'pgsql' => [ 'driver' => 'pgsql', 'host' => 'localhost', 'database' => 'homestead', 'username' => 'homestead', 'password' => 'secret', 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', ], ], ]; 

而我得到了同样的错误: PDOException(1045)HELP

SQLSTATE [HY000] [1045]拒绝用户'宅地'@'localhost'的访问(使用密码:YES)

任何想法可以解决这个问题? 谢谢

尝试在你的mysql数据库中为你的用户'homestead'添加特权。

login到MySQL并添加像这样的权限:

 mysql -u root -p 

input您的MySQL密码

 mysql > grant all privileges on homestead *.* to 'homestead'@'localhost' identified by 'password'; 

'密码'在这里是在你的database.php

如果你在本地环境中,database.php的path是:

yourporjectfolder /应用/configuration/本地

 mysql > FLUSH PRIVILEGES;