用户“homestead”@“localhost”访问被拒绝(使用密码:YES)

时间:2022-05-28 03:06:07

I'm on a Mac OS Yosemite using Laravel 5.0.

我在使用Laravel 5.0的Mac OS Yosemite。

While in my local environment, I run php artisan migrate I keep getting :

在我的本地环境中,我运行php artisan迁移,不断得到:

用户“homestead”@“localhost”访问被拒绝(使用密码:YES)

Configuration

配置

Here is my .env

这是我.env

APP_ENV=local
APP_DEBUG=true
APP_KEY=*****

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

app\config\database.php

app \ config \ database.php

   'mysql'       => [
    'driver'      => 'mysql',
    'host'        => env('DB_HOST', 'localhost'),
    'database'    => env('DB_DATABASE', 'homestead'),
    'username'    => env('DB_USERNAME', 'homestead'),
    'password'    => env('DB_PASSWORD', 'secret'),
    'unix_socket' => '/tmp/mysql.sock',
    'charset'     => 'utf8',
    'collation'   => 'utf8_unicode_ci',
    'prefix'      => '',
    'strict'      => false,
    ]

How do I avoid this kind of error ?

如何避免这种错误呢?

I've tried :

我试过了:


1

in app/database.php

在app / database.php

Replace localhost with 127.0.0.1

替换localhost 127.0.0.1

'host'=> env('DB_HOST', 'localhost') -->'host' => env('DB_HOST', '127.0.0.1')

“主机”= > env(“DB_HOST”、“localhost”)——> '主机' = > env(‘DB_HOST’,‘127.0.0.1)

Also, in .env

另外,在.env

DB_HOST=localhost --> DB_HOST=127.0.0.1

DB_HOST = localhost - - > DB_HOST = 127.0.0.1


2

Try specify environment

尝试指定环境

php artisan migrate --env=local

php工匠——env =地方迁移


3

Check to see if the MySQL is running by run

检查MySQL是否运行。

mysqladmin -u homestead -p status Enter password: secret

mysqladmin -u homestead -p状态输入密码: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

运行时间:21281线程:3个问题:274个慢查询:0打开:327个刷新表:1个打开的表:每秒80个查询avg: 0.012

Which mean it's running.

这意味着它的运行。


4

Check MySQL UNIX Socket (This step work for me)

检查MySQL UNIX套接字(这一步对我有用)

22 个解决方案

#1


170  

The reason of Access denied for user ‘homestead’@’localhost’ laravel 5 error is caching-issue of the .env.php file cause Laravel 5 is using environment based configuration in your .env file.

用户“homestead”@“localhost”laravel 5访问被拒绝的原因是.env的缓存问题。php文件导致Laravel 5正在您的.env文件中使用基于环境的配置。

1. Go to your application root directory and open .env file (In ubuntu may be it’s hidden so press ctrl+h to show hidden files & if you are in terminal then type : ls -a to show hidden files) in your editor and change database configuration setting. then save your .env file

1。进入你的应用程序根目录并在你的编辑器中打开。env文件(在ubuntu中它可能是隐藏的,所以按ctrl+h来显示隐藏的文件&如果你在终端,那么输入:ls -a来显示隐藏的文件)并更改数据库配置设置。然后保存.env文件

DB_HOST=localhost
DB_DATABASE=laravelu
DB_USERNAME=root
DB_PASSWORD=''

2. then restart your apache server/web server. and refresh your page and you have done

2。然后重新启动apache服务器/web服务器。刷新你的页面,你就完成了

3. If still issue try to run below command to clear the old configuration cache file.

3所示。如果仍然有问题,请尝试运行以下命令清除旧的配置缓存文件。

php artisan config:clear

Now you are done with the error

现在,错误已经完成了

#2


37  

TLDR: You need to stop the server Ctrl + c and start again using php artisan serve

您需要停止服务器并使用php artisan服务重新开始


Details:

If you are using Laravel, and have started local dev server already by php artisan serve

如果您正在使用Laravel,并且已经通过php artisan服务启动了本地开发服务器

And after having above server already running, you change your database server related stuff in .env file. Like moving from MySQL to SQLite or something. You need to make sure that you stop above process i.e. Ctrcl C or anything which stop the process. And then restart Artisan Serve again i.e. y php artisan serve and refresh your browser and your issue related to database will be fixed. This is what worked for me for Laravel 5.3

在服务器已经运行之后,您可以在.env文件中更改数据库服务器相关的内容。比如从MySQL到SQLite之类的。您需要确保停止在进程之上,例如ctrl + C或任何停止进程的东西。然后重新启动Artisan服务,即y php Artisan服务并刷新浏览器,您与数据库相关的问题将得到解决。这就是我为Laravel 5.3所做的

#3


29  

Two way to solve it

有两种方法

First way (Not recommended)

第一个方法(不推荐)

Open your database config file (laravel_root/config/database.php) & search for the below code block.

打开数据库配置文件(laravel_root/config/database.php)并搜索下面的代码块。

        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'blog'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', ''),

Change the code block as below

将代码块更改为如下所示

        'host'      => 'yourHostName',
        'database'  => 'YourDatabastName',
        'username'  => 'YoutDatabaseUsername',
        'password'  => 'YourDatabasePassword',

Second way (Recommended by Laravel)

第二种方法(Laravel推荐)

Check your Laravel root there have a file call .env if not exist, look for .env.example, copy/rename it as .env after that the file looks blow !

检查你的Laravel根,那里有一个文件调用。env如果不存在,查找。env。例如,将它复制/重命名为.env,然后文件看起来很糟糕!

APP_ENV=local
APP_DEBUG=true
APP_KEY=someRandomNumber

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null

Modify the below block as follow

修改下面的块,如下所示

DB_HOST=yourHostName
DB_DATABASE=yourDatabaseName
DB_USERNAME=yourDatabaseUsername
DB_PASSWORD=youPassword

Now it will work fine.

现在一切都会好起来。

#4


16  

if you are using php artisan migrate NOT from vagrant box but from host machine then you must define inside the .env the ip of the box 192.168.10.10

如果您使用的是php artisan,那么您必须在.env中定义box 192.168.10.10的ip,而不是从vagrant box迁移,而是从主机迁移

and obviously set permission to homestead user from your ip something like

显然,从你的ip中给homestead用户设置权限

grant all privileges on *.* to 'homestead'@% identified by 'secret';

in .env file

在.env文件

DB_HOST=192.168.10.10
DB_DATABASE=homestead
DB_USERNAME=homestead

#5


16  

If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.

如果您正在使用PHP的默认web服务器(例如PHP artisan服务),您需要在更改.env文件值之后重新启动服务器。

#6


9  

When you install Homestead, this creates a default "homestead" database in the VM. You should SSH into the VM homestead ssh and run your migrations from there. If you are working locally with no VM, you'll need to create your database manually. By default, the database should be called homestead, the username is homestead and the password is secret.

安装Homestead时,会在VM中创建一个默认的“Homestead”数据库。您应该SSH到VM homestead SSH并从那里运行您的迁移。如果您在本地工作时没有使用VM,那么需要手动创建数据库。默认情况下,数据库应该被称为homestead,用户名是homestead,密码是secret。

check this thread on laracasts or this blog post for more details

查看laracast或这篇博客文章上的这篇文章,了解更多细节


if you are getting

如果你得到

[PDOException] SQLSTATE[HY000] [2002] No such file or directory

try changing "host" in the /app/config/database.php file from "localhost" to "127.0.0.1" . you can find more details and other fixes here on this thread.

尝试在/app/config/数据库中更改“host”。php文件从“localhost”到“127.0.0.1”。您可以在此线程中找到更多的细节和其他修复。

Also check whether you have specified the correct unix_socket . check this thread .

还要检查您是否指定了正确的unix_socket。检查这个线程。

#7


9  

In Windows PC Follow below.

在Windows PC下面。


  1. Access the Root folder of your application.

    访问应用程序的根文件夹。

  2. Edit the .env file

    编辑.env文件

用户“homestead”@“localhost”访问被拒绝(使用密码:YES)

用户“homestead”@“localhost”访问被拒绝(使用密码:YES)

Edit the Highlighted and change the UserName and the password adn The database Name accordingly.

编辑突出显示的内容,并相应地更改用户名和密码以及数据库名。

#8


7  

Check MySQL UNIX Socket

Find unix_socket location using MySQL

使用MySQL找到unix_socket位置

mysql -u homestead -p

mysql - u家园- p

mysql> show variables like '%sock%';
+-----------------------------------------+-----------------------------+
| Variable_name                           | Value                       |
+-----------------------------------------+-----------------------------+
| performance_schema_max_socket_classes   | 10                          |
| performance_schema_max_socket_instances | 322                         |
| socket                                  | /var/run/mysqld/mysqld.sock |
+-----------------------------------------+-----------------------------+
3 rows in set (0.00 sec)

Then I go to config/database.php

然后转到config/database.php

I update this line : 'unix_socket' => '/tmp/mysql.sock',

我更新这一行:'unix_socket' => '/tmp/mysql.sock',

to : 'unix_socket' => '/var/run/mysqld/mysqld.sock',

to: 'unix_socket' => '/var/run/mysqld/mysqld.sock'

That's it. It works for my as my 4th try.I hope these steps help someone. :D

就是这样。这是我的第四次尝试。我希望这些步骤对某人有所帮助。:D

#9


7  

I had the same issue and in the end It turned out that I just had to restart the server and start again

我有同样的问题,最后我不得不重新启动服务器并重新启动。

Ctrl + c then

Ctrl + c然后

php artisan serve

#10


5  

Sometime in the future. Try to clear your config first

在未来的某个时候。尝试先清除配置

php artisan config:clear. 

Close all the terminal /cmd windows and then restart terminal/CMD and this should get rid of the error message. See if it works.

关闭所有的终端/cmd窗口,然后重新启动终端/cmd,这将消除错误消息。看看它的工作原理。

#11


5  

After change .env with the new configuration, you have to stop the server and run it again (php artisan serve). Cause laravel gets the environment when it's initialized the server. If you don't restart, you will change the .env asking yourself why the changes aren't taking place!!

在使用新配置修改.env之后,必须停止服务器并再次运行它(php artisan服务)。因为laravel在初始化服务器时获取环境。如果你不重新启动,你将改变。env问你自己为什么变化没有发生!!

#12


4  

i using laravel 5.* i figure i have a file call .env in the root of the project that look something like this:

我使用laravel 5。*我认为我在项目的根目录中有一个文件call .env,看起来像这样:

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

And that was over writing the bd configuration so you can wheather deleted those config vars so laravel take the configuration under /config or set up your configuration here.

这是在写bd配置的时候你可以把那些配置文件删除所以laravel把配置放在/配置下或者在这里设置你的配置。

I did the second and it works for me :)

我做了第二件,这对我很有效:)

#13


4  

Got it! Log in as root and grant homestead@localhost the rights to everything.

得到它!以root身份登录并授予homestead@localhost所有权限。

From your terminal:

从您的终端:

$ homestead ssh

$ mysql -u root -p

Enter password: secret

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

Query OK, 0 rows affected (0.00 sec)
exit

Now homesteads regular user has access to all of your tables, and as such, should be able to run things like migrations.

现在,homesteads常规用户可以访问您的所有表,因此,应该能够运行诸如迁移之类的操作。

#14


3  

I just wanted to post this because this issue frustrated me for about 3 hours today. I have not tried any of the methods listed in the other answers, though they all seem reasonable. In fact, I was just about to try going through each of the above proposed solutions, but somehow I got this stroke of inspiration. Here is what worked for me to get me back working -- YMMV:

我只是想发这篇文章,因为今天这个问题让我沮丧了3个小时。我还没有尝试过其他答案中列出的任何一种方法,尽管它们看起来都很合理。事实上,我正要试着去看看上面提出的每一个解决方案,但不知何故,我得到了灵感。下面是我的工作,让我重新开始工作——YMMV:

1) Find your .env file. 2) Rename your .env file to something else. Laravel 5 must be using this file as an override for settings somewhere else in the framework. I renamed mine to .env.old 3) You may need to restart your web server, but I did not have to.

1)找到你的。env文件。2)将.env文件重命名为其他文件。Laravel 5必须使用这个文件作为框架中其他地方的设置的覆盖。我把我的名字改成了。env。老3)您可能需要重新启动web服务器,但我不必这样做。

Good luck!

好运!

#15


3  

Check your ".env" file in the root folder. is it correct?

检查你的”。在根文件夹中的env文件。是正确的吗?

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

#16


2  

You have to run the $ php artisan migrate command from within Homestead, not your Mac.

您必须在Homestead中运行$ php artisan迁移命令,而不是您的Mac。

#17


2  

i have find solution

我已经找到解决方案

  1. Go to your application root directory and open .env file (In ubuntu may be it’s hidden so press ctrl+h to show hidden files) in your editor and change database configuration setting. then save your .env file

    进入你的应用程序根目录并打开.env文件(在ubuntu中可能是隐藏的,所以按ctrl+h显示隐藏文件)在编辑器中,并更改数据库配置设置。然后保存.env文件

  2. then restart your apache server/web server. and refresh your page and you have done

    然后重新启动apache服务器/web服务器。刷新你的页面,你就完成了

  3. If still issue try to run below command to clear the old configuration cache file.
  4. 如果仍然有问题,请尝试运行以下命令清除旧的配置缓存文件。

This worked for me gl ...

这对我很有用……

#18


1  

Log into MYSQL - use the mysql database.

登录到MYSQL -使用MYSQL数据库。

Select * from User;

从用户选择*;

Make sure that your HOST column is correct. It should be the host that you are connecting from (your application server) be it IP address, or DNS name. Also '%' will work (meaning wildcard) but will not be secure.

确保您的主机列是正确的。它应该是您连接的主机(您的应用程序服务器)是它的IP地址,或DNS名称。同样,'%'也可以工作(表示通配符),但是不安全。

#19


1  

Check your .env file, if you have edited any of the variables, kindly restart laravel server, and your problem will be solved

检查您的.env文件,如果您编辑了任何变量,请重新启动laravel服务器,您的问题将得到解决

#20


0  

I had the same issue using SQLite. My problem was that DB_DATABASE was pointing to the wrong file location.

我在使用SQLite时遇到了同样的问题。我的问题是DB_DATABASE指向错误的文件位置。

Create the sqlite file with the touch command and output the file path using php artisan tinker.

使用touch命令创建sqlite文件,并使用php artisan tinker输出文件路径。

$ touch database/database.sqlite
$ php artisan tinker
Psy Shell v0.8.0 (PHP 5.6.27 — cli) by Justin Hileman
>>> database_path(‘database.sqlite’)
=> "/Users/connorleech/Projects/laravel-5-rest-api/database/database.sqlite"

Then output that exact path to the DB_DATABASE variable.

然后输出到DB_DATABASE变量的确切路径。

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=/Users/connorleech/Projects/laravel-5-rest-api/database/database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret

Without the correct path you will get the access denied error

如果没有正确的路径,您将获得访问拒绝错误

#21


0  

If you have an error returning something like PDOException in Connector.php line 55: SQLSTATE[HY000] [1049] Unknown database 'laravelu' is due to you are changing your batabase config as DB_DATABASE=laravelu. So for now you either:

如果在连接器中返回了类似PDOException的错误。php第55行:SQLSTATE[HY000][1049]未知数据库“laravelu”是由于您将batabase配置更改为DB_DATABASE=laravelu。现在你也可以:

  1. Change the DB_DATABASE=[yourdatabase] or
  2. DB_DATABASE =[yourdatabase]或改变
  3. create a database called laravelu in your phpmyadmin
  4. 在phpmyadmin中创建一个名为laravelu的数据库。

this should be able to solve it

这应该能解出来。

#22


0  

A. After updating the .env file with database settings, clear larval setting by "running php artisan config:clear"

A.使用数据库设置更新.env文件后,通过“运行php artisan配置:clear”清除幼虫设置

B. Please make sure you restart your apache server / rerun the "php artisan serve" command for your settings to take effect.

请确保重新启动您的apache服务器/重新运行“php artisan服务”命令,以使您的设置生效。

#1


170  

The reason of Access denied for user ‘homestead’@’localhost’ laravel 5 error is caching-issue of the .env.php file cause Laravel 5 is using environment based configuration in your .env file.

用户“homestead”@“localhost”laravel 5访问被拒绝的原因是.env的缓存问题。php文件导致Laravel 5正在您的.env文件中使用基于环境的配置。

1. Go to your application root directory and open .env file (In ubuntu may be it’s hidden so press ctrl+h to show hidden files & if you are in terminal then type : ls -a to show hidden files) in your editor and change database configuration setting. then save your .env file

1。进入你的应用程序根目录并在你的编辑器中打开。env文件(在ubuntu中它可能是隐藏的,所以按ctrl+h来显示隐藏的文件&如果你在终端,那么输入:ls -a来显示隐藏的文件)并更改数据库配置设置。然后保存.env文件

DB_HOST=localhost
DB_DATABASE=laravelu
DB_USERNAME=root
DB_PASSWORD=''

2. then restart your apache server/web server. and refresh your page and you have done

2。然后重新启动apache服务器/web服务器。刷新你的页面,你就完成了

3. If still issue try to run below command to clear the old configuration cache file.

3所示。如果仍然有问题,请尝试运行以下命令清除旧的配置缓存文件。

php artisan config:clear

Now you are done with the error

现在,错误已经完成了

#2


37  

TLDR: You need to stop the server Ctrl + c and start again using php artisan serve

您需要停止服务器并使用php artisan服务重新开始


Details:

If you are using Laravel, and have started local dev server already by php artisan serve

如果您正在使用Laravel,并且已经通过php artisan服务启动了本地开发服务器

And after having above server already running, you change your database server related stuff in .env file. Like moving from MySQL to SQLite or something. You need to make sure that you stop above process i.e. Ctrcl C or anything which stop the process. And then restart Artisan Serve again i.e. y php artisan serve and refresh your browser and your issue related to database will be fixed. This is what worked for me for Laravel 5.3

在服务器已经运行之后,您可以在.env文件中更改数据库服务器相关的内容。比如从MySQL到SQLite之类的。您需要确保停止在进程之上,例如ctrl + C或任何停止进程的东西。然后重新启动Artisan服务,即y php Artisan服务并刷新浏览器,您与数据库相关的问题将得到解决。这就是我为Laravel 5.3所做的

#3


29  

Two way to solve it

有两种方法

First way (Not recommended)

第一个方法(不推荐)

Open your database config file (laravel_root/config/database.php) & search for the below code block.

打开数据库配置文件(laravel_root/config/database.php)并搜索下面的代码块。

        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'blog'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', ''),

Change the code block as below

将代码块更改为如下所示

        'host'      => 'yourHostName',
        'database'  => 'YourDatabastName',
        'username'  => 'YoutDatabaseUsername',
        'password'  => 'YourDatabasePassword',

Second way (Recommended by Laravel)

第二种方法(Laravel推荐)

Check your Laravel root there have a file call .env if not exist, look for .env.example, copy/rename it as .env after that the file looks blow !

检查你的Laravel根,那里有一个文件调用。env如果不存在,查找。env。例如,将它复制/重命名为.env,然后文件看起来很糟糕!

APP_ENV=local
APP_DEBUG=true
APP_KEY=someRandomNumber

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null

Modify the below block as follow

修改下面的块,如下所示

DB_HOST=yourHostName
DB_DATABASE=yourDatabaseName
DB_USERNAME=yourDatabaseUsername
DB_PASSWORD=youPassword

Now it will work fine.

现在一切都会好起来。

#4


16  

if you are using php artisan migrate NOT from vagrant box but from host machine then you must define inside the .env the ip of the box 192.168.10.10

如果您使用的是php artisan,那么您必须在.env中定义box 192.168.10.10的ip,而不是从vagrant box迁移,而是从主机迁移

and obviously set permission to homestead user from your ip something like

显然,从你的ip中给homestead用户设置权限

grant all privileges on *.* to 'homestead'@% identified by 'secret';

in .env file

在.env文件

DB_HOST=192.168.10.10
DB_DATABASE=homestead
DB_USERNAME=homestead

#5


16  

If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.

如果您正在使用PHP的默认web服务器(例如PHP artisan服务),您需要在更改.env文件值之后重新启动服务器。

#6


9  

When you install Homestead, this creates a default "homestead" database in the VM. You should SSH into the VM homestead ssh and run your migrations from there. If you are working locally with no VM, you'll need to create your database manually. By default, the database should be called homestead, the username is homestead and the password is secret.

安装Homestead时,会在VM中创建一个默认的“Homestead”数据库。您应该SSH到VM homestead SSH并从那里运行您的迁移。如果您在本地工作时没有使用VM,那么需要手动创建数据库。默认情况下,数据库应该被称为homestead,用户名是homestead,密码是secret。

check this thread on laracasts or this blog post for more details

查看laracast或这篇博客文章上的这篇文章,了解更多细节


if you are getting

如果你得到

[PDOException] SQLSTATE[HY000] [2002] No such file or directory

try changing "host" in the /app/config/database.php file from "localhost" to "127.0.0.1" . you can find more details and other fixes here on this thread.

尝试在/app/config/数据库中更改“host”。php文件从“localhost”到“127.0.0.1”。您可以在此线程中找到更多的细节和其他修复。

Also check whether you have specified the correct unix_socket . check this thread .

还要检查您是否指定了正确的unix_socket。检查这个线程。

#7


9  

In Windows PC Follow below.

在Windows PC下面。


  1. Access the Root folder of your application.

    访问应用程序的根文件夹。

  2. Edit the .env file

    编辑.env文件

用户“homestead”@“localhost”访问被拒绝(使用密码:YES)

用户“homestead”@“localhost”访问被拒绝(使用密码:YES)

Edit the Highlighted and change the UserName and the password adn The database Name accordingly.

编辑突出显示的内容,并相应地更改用户名和密码以及数据库名。

#8


7  

Check MySQL UNIX Socket

Find unix_socket location using MySQL

使用MySQL找到unix_socket位置

mysql -u homestead -p

mysql - u家园- p

mysql> show variables like '%sock%';
+-----------------------------------------+-----------------------------+
| Variable_name                           | Value                       |
+-----------------------------------------+-----------------------------+
| performance_schema_max_socket_classes   | 10                          |
| performance_schema_max_socket_instances | 322                         |
| socket                                  | /var/run/mysqld/mysqld.sock |
+-----------------------------------------+-----------------------------+
3 rows in set (0.00 sec)

Then I go to config/database.php

然后转到config/database.php

I update this line : 'unix_socket' => '/tmp/mysql.sock',

我更新这一行:'unix_socket' => '/tmp/mysql.sock',

to : 'unix_socket' => '/var/run/mysqld/mysqld.sock',

to: 'unix_socket' => '/var/run/mysqld/mysqld.sock'

That's it. It works for my as my 4th try.I hope these steps help someone. :D

就是这样。这是我的第四次尝试。我希望这些步骤对某人有所帮助。:D

#9


7  

I had the same issue and in the end It turned out that I just had to restart the server and start again

我有同样的问题,最后我不得不重新启动服务器并重新启动。

Ctrl + c then

Ctrl + c然后

php artisan serve

#10


5  

Sometime in the future. Try to clear your config first

在未来的某个时候。尝试先清除配置

php artisan config:clear. 

Close all the terminal /cmd windows and then restart terminal/CMD and this should get rid of the error message. See if it works.

关闭所有的终端/cmd窗口,然后重新启动终端/cmd,这将消除错误消息。看看它的工作原理。

#11


5  

After change .env with the new configuration, you have to stop the server and run it again (php artisan serve). Cause laravel gets the environment when it's initialized the server. If you don't restart, you will change the .env asking yourself why the changes aren't taking place!!

在使用新配置修改.env之后,必须停止服务器并再次运行它(php artisan服务)。因为laravel在初始化服务器时获取环境。如果你不重新启动,你将改变。env问你自己为什么变化没有发生!!

#12


4  

i using laravel 5.* i figure i have a file call .env in the root of the project that look something like this:

我使用laravel 5。*我认为我在项目的根目录中有一个文件call .env,看起来像这样:

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

And that was over writing the bd configuration so you can wheather deleted those config vars so laravel take the configuration under /config or set up your configuration here.

这是在写bd配置的时候你可以把那些配置文件删除所以laravel把配置放在/配置下或者在这里设置你的配置。

I did the second and it works for me :)

我做了第二件,这对我很有效:)

#13


4  

Got it! Log in as root and grant homestead@localhost the rights to everything.

得到它!以root身份登录并授予homestead@localhost所有权限。

From your terminal:

从您的终端:

$ homestead ssh

$ mysql -u root -p

Enter password: secret

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

Query OK, 0 rows affected (0.00 sec)
exit

Now homesteads regular user has access to all of your tables, and as such, should be able to run things like migrations.

现在,homesteads常规用户可以访问您的所有表,因此,应该能够运行诸如迁移之类的操作。

#14


3  

I just wanted to post this because this issue frustrated me for about 3 hours today. I have not tried any of the methods listed in the other answers, though they all seem reasonable. In fact, I was just about to try going through each of the above proposed solutions, but somehow I got this stroke of inspiration. Here is what worked for me to get me back working -- YMMV:

我只是想发这篇文章,因为今天这个问题让我沮丧了3个小时。我还没有尝试过其他答案中列出的任何一种方法,尽管它们看起来都很合理。事实上,我正要试着去看看上面提出的每一个解决方案,但不知何故,我得到了灵感。下面是我的工作,让我重新开始工作——YMMV:

1) Find your .env file. 2) Rename your .env file to something else. Laravel 5 must be using this file as an override for settings somewhere else in the framework. I renamed mine to .env.old 3) You may need to restart your web server, but I did not have to.

1)找到你的。env文件。2)将.env文件重命名为其他文件。Laravel 5必须使用这个文件作为框架中其他地方的设置的覆盖。我把我的名字改成了。env。老3)您可能需要重新启动web服务器,但我不必这样做。

Good luck!

好运!

#15


3  

Check your ".env" file in the root folder. is it correct?

检查你的”。在根文件夹中的env文件。是正确的吗?

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

#16


2  

You have to run the $ php artisan migrate command from within Homestead, not your Mac.

您必须在Homestead中运行$ php artisan迁移命令,而不是您的Mac。

#17


2  

i have find solution

我已经找到解决方案

  1. Go to your application root directory and open .env file (In ubuntu may be it’s hidden so press ctrl+h to show hidden files) in your editor and change database configuration setting. then save your .env file

    进入你的应用程序根目录并打开.env文件(在ubuntu中可能是隐藏的,所以按ctrl+h显示隐藏文件)在编辑器中,并更改数据库配置设置。然后保存.env文件

  2. then restart your apache server/web server. and refresh your page and you have done

    然后重新启动apache服务器/web服务器。刷新你的页面,你就完成了

  3. If still issue try to run below command to clear the old configuration cache file.
  4. 如果仍然有问题,请尝试运行以下命令清除旧的配置缓存文件。

This worked for me gl ...

这对我很有用……

#18


1  

Log into MYSQL - use the mysql database.

登录到MYSQL -使用MYSQL数据库。

Select * from User;

从用户选择*;

Make sure that your HOST column is correct. It should be the host that you are connecting from (your application server) be it IP address, or DNS name. Also '%' will work (meaning wildcard) but will not be secure.

确保您的主机列是正确的。它应该是您连接的主机(您的应用程序服务器)是它的IP地址,或DNS名称。同样,'%'也可以工作(表示通配符),但是不安全。

#19


1  

Check your .env file, if you have edited any of the variables, kindly restart laravel server, and your problem will be solved

检查您的.env文件,如果您编辑了任何变量,请重新启动laravel服务器,您的问题将得到解决

#20


0  

I had the same issue using SQLite. My problem was that DB_DATABASE was pointing to the wrong file location.

我在使用SQLite时遇到了同样的问题。我的问题是DB_DATABASE指向错误的文件位置。

Create the sqlite file with the touch command and output the file path using php artisan tinker.

使用touch命令创建sqlite文件,并使用php artisan tinker输出文件路径。

$ touch database/database.sqlite
$ php artisan tinker
Psy Shell v0.8.0 (PHP 5.6.27 — cli) by Justin Hileman
>>> database_path(‘database.sqlite’)
=> "/Users/connorleech/Projects/laravel-5-rest-api/database/database.sqlite"

Then output that exact path to the DB_DATABASE variable.

然后输出到DB_DATABASE变量的确切路径。

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=/Users/connorleech/Projects/laravel-5-rest-api/database/database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret

Without the correct path you will get the access denied error

如果没有正确的路径,您将获得访问拒绝错误

#21


0  

If you have an error returning something like PDOException in Connector.php line 55: SQLSTATE[HY000] [1049] Unknown database 'laravelu' is due to you are changing your batabase config as DB_DATABASE=laravelu. So for now you either:

如果在连接器中返回了类似PDOException的错误。php第55行:SQLSTATE[HY000][1049]未知数据库“laravelu”是由于您将batabase配置更改为DB_DATABASE=laravelu。现在你也可以:

  1. Change the DB_DATABASE=[yourdatabase] or
  2. DB_DATABASE =[yourdatabase]或改变
  3. create a database called laravelu in your phpmyadmin
  4. 在phpmyadmin中创建一个名为laravelu的数据库。

this should be able to solve it

这应该能解出来。

#22


0  

A. After updating the .env file with database settings, clear larval setting by "running php artisan config:clear"

A.使用数据库设置更新.env文件后,通过“运行php artisan配置:clear”清除幼虫设置

B. Please make sure you restart your apache server / rerun the "php artisan serve" command for your settings to take effect.

请确保重新启动您的apache服务器/重新运行“php artisan服务”命令,以使您的设置生效。