php artisan migrate 的 Laravel 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35211751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:10:59  来源:igfitidea点击:

Laravel error with php artisan migrate

phplaravelubuntucomposer-php

提问by Mr Gibbous

I'm trying to follow this guide: https://laravel.com/docs/5.2/quickstart

我正在尝试遵循本指南:https: //laravel.com/docs/5.2/quickstart

I'm running ubuntu 14.04 on aws. I'm using laravel 5.2. I'm new to laravel (and aws too for that matter), I've done everything in the guide and get this error.

我在 aws 上运行 ubuntu 14.04。我正在使用 Laravel 5.2。我是 laravel 的新手(对于这件事,aws 也是如此),我已经完成了指南中的所有内容并收到了这个错误。

When I run:

当我运行时:

php artisan migrate

php工匠迁移

I get the following error:

我收到以下错误:

[PDOException]

SQLSTATE[28000] [1045] Access denied for user 'homestead'@'localhost' (usin g password: YES)

[PDO 异常]

SQLSTATE[28000] [1045] 用户“homestead”@“localhost”的访问被拒绝(使用密码:YES)

The .env file looks like this:

.env 文件如下所示:

APP_ENV=local APP_DEBUG=true APP_KEY=hXP0uBJkQos3cHK7D8f6LVx2SLuLAuyv

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

CACHE_DRIVER=file 
SESSION_DRIVER=file 
QUEUE_DRIVER=sync

REDIS_HOST=localhost 
REDIS_PASSWORD=null 
REDIS_PORT=6379

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

Edit: Okay, so I guess this problem was due to a lack of understanding of ubuntu, mysql and laravel. I followed the guide in the link above exactly but I guess it was meant for people running homestead. It looks like on an ubuntu server you have to manually create the database (guess it seems obvious to most).

编辑:好的,所以我猜这个问题是由于对 ubuntu、mysql 和 laravel 缺乏了解。我完全按照上面链接中的指南进行操作,但我想它是为运行宅基地的人准备的。看起来您必须在 ubuntu 服务器上手动创建数据库(猜猜这对大多数人来说似乎很明显)。

So login to mysql with:

所以登录到mysql:

mysql -u root -p

Then enter the password when you are prompted for it.

然后在提示时输入密码。

It's probably not a good idea to use root but I'm just learning so yea. The password you enter here is the same password you have to enter in the .env file in the laravel root directory.

使用 root 可能不是一个好主意,但我只是在学习,是的。您在此处输入的密码与您必须在 laravel 根目录下的 .env 文件中输入的密码相同。

Once logged into mysql enter:

登录mysql后输入:

mysql> create database homestead;

This creates a database with the same name as the one specified in the .env file DB_DATABASE=homestead. I should probably change it from homestead as I'm not using homestead :/

这将创建一个与 .env 文件 DB_DATABASE=homestead 中指定的名称相同的数据库。我可能应该从宅基地改变它,因为我没有使用宅基地:/

The DB_USERNAME is the same username that we use to log into mysql so

DB_USERNAME 与我们用于登录 mysql 的用户名相同,因此

DB_USERNAME = root

While the password is the same password we used to log into mysql.

虽然密码与我们用来登录 mysql 的密码相同。

This probably all seems obvious but I'm new and had no idea. It also wasn't covered in the quickstart guide on the laravel website. Maybe I didn't follow it accurately, if so let me know.

这可能看起来很明显,但我是新手,不知道。laravel 网站上的快速入门指南也没有涵盖它。也许我没有准确地遵循它,如果是这样让我知道。

Cheers

干杯

回答by enriqg9

As I mentioned you, you need to login to MySQL via terminal mysql -u root -p, where root is the MySQL user, then input your password, then just create the database using the SQL CREATE DATABASE my_db;where my_dbis the database name and finally just update your .env file with your database and credentials.

正如我提到的,您需要通过终端登录 MySQL mysql -u root -p,其中 root 是 MySQL 用户,然后输入您的密码,然后使用 SQL 创建数据库,CREATE DATABASE my_db;其中my_db数据库名称,最后只用您的数据库更新您的 .env 文件和凭据。

回答by Qammar Feroz

You need to update .env file with correct credentials, for example

例如,您需要使用正确的凭据更新 .env 文件

DB_HOST=localhost 
DB_DATABASE=db_name
DB_USERNAME=db_username
DB_PASSWORD=db_password

to correctly connect with the database. If you have not created the database before, you can create it through PHPMyAdmin.

正确连接数据库。如果之前没有创建过数据库,可以通过 PHPMyAdmin 来创建。