我刚刚在Laravel 5.1中构建了我的新应用程序,我试图推动它。当我尝试编写器安装时,我收到此错误。
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)
Script php artisan clear-compiled handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
我在本地和制作上都使用环境文件,所以我不知道最近会发生什么。有什么想法吗?
就像我的环境文件没有被伪造的那样......
配置/ datasbase.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' => storage_path('database.sqlite'),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'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,
],
],
];
答案 0 :(得分:1)
之所以发生这种情况,是因为我正在使用伪造的“安装回购”功能来安装我的完整项目。现在因为服务器上没有设置环境,所以在安装时失败了。
为了解决这个问题,我不得不对生产数据库凭据进行硬编码,安装repo然后创建env文件。然后,一旦完成,删除硬编码凭证(我不知道)。
似乎在安装之前设置.env也不起作用。因此,如果从构建开始就在服务器上安装了repo,就不会遇到这类问题。
但我的项目现已正常运行。谢谢你的回复。
答案 1 :(得分:1)
发生这种情况的原因是因为forge正在您的项目上运行post install命令,并且您可能正在访问您的某个服务提供商中的数据库,因为它可能是您想要附加到您的视图的变量,请尝试评论服务提供程序中的代码,安装存储库然后再次推送代码它应该可以正常工作
答案 2 :(得分:0)
确保MySQL
用户在连接MySQL
时拥有给定ip的所有访问权限。如需进一步参考,请浏览以下链接。
http://tech2smooth.blogspot.in/2014/09/create-mysql-user-and-grant-permission.html
答案 3 :(得分:0)
如果没有看到.env文件,很难说肯定,但看起来它从某个地方拿起用户名 - 默认是&#39;伪造&#39;然而错误消息的用户名为空字符串 - &#39;&#39; @localhost。
检查你的env文件,确保=后面没有空格,并且变量名与数据库配置中的变量名匹配。我还有一些问题需要将密码和其他具有特殊字符的值包装在&#39;&#39;中。最后,请记住这个案例很重要 - 我已经看到了一切都在本地工作但在开发服务器上失败的问题,因为有人改变了变量的情况。我的mac并不关心,但ubuntu服务器确实如此。
答案 4 :(得分:0)
试试这个
1
in app/database.php
Replace localhost with 127.0.0.1
'host'=> env('DB_HOST', 'localhost') -->'host' => env('DB_HOST', '127.0.0.1')
Also, in .env
DB_HOST=localhost --> DB_HOST=127.0.0.1
2
Try specify environment
php artisan migrate --env=local
3
Check to see if the MySQL is running by run
mysqladmin -u homestead -p status Enter password: secret
I got
Uptime: 21281 Threads: 3 Questions: 274 Slow queries: 0 Opens: 327 Flush tables: 1 Open tables: 80 Queries per second avg: 0.012
Which mean it's running.
4
Check MySQL UNIX Socket
5 确保你的.env文件看起来像这样:
APP_ENV=local
APP_DEBUG=true
APP_KEY=YOURAPPKEY
DB_HOST=localhost
DB_DATABASE=YOURDBNAME
DB_USERNAME=YOURPHPMYADMINUSERNAME
DB_PASSWORD=YOURPHPMYADMINPASS
6
try changing localhost into 127.0.0.1 in .env DB_HOST or try add your mysql port