Artisan Migrate 访问被拒绝
Posted
技术标签:
【中文标题】Artisan Migrate 访问被拒绝【英文标题】:Artisan Migrate Access Denied 【发布时间】:2018-11-17 15:30:05 【问题描述】:我正在设置一个 Laravel 环境。因此,我下载了 XAMPP 并相应地配置了我的虚拟主机文件。然后,我设置 mysql 并运行以下命令:
-
作曲家安装
npm 安装
php artisan(确认我有 artisan)
php工匠迁移
在运行第 4 次之后,我在图片中收到以下错误。
C:\Users\Aslam\Desktop\Pfera_application\pfera-web>php artisan migrate -v
Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations)
at C:\Users\Aslam\Desktop\Pfera_application\pfera-web\vendor\laravel\framework\src\Illuminate\Database\Connection.php: 664
660: // If an exception occurs when attempting to run a query, we'll format the error
661: // message to include the bindings with SQL, which will make this exception a
662: // lot more helpful to the developer instead of just the database's errors.
663: catch (Exception $e)
664: throw new QueryException(
665: $query, $this->prepareBindings($bindings), $e
666: );
667:
668:
669: return $result;
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES)")
C:\Users\Aslam\Desktop\Pfera_application\pfera-web\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php : 50
请帮忙!!!非常感谢!
PS,这里是database.php文件:
<?php
return [
/*
|--------------------------------------------------------------------------
| 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', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'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' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
这是我的 .env 文件:
## REAL KEY REMOVED FOR PLAIN TEXT TRANSFER
## SEE http://laravel-recipes.com/recipes/283/generating-a-new-application-key FOR GENERATING YOUR OWN KEY, DO THIS BEFORE RUNNING ANY SEEDS
APP_NAME=Pfera
APP_ENV=staging
APP_KEY=base64:E8vEONwbkikyy/7IsRpNg/kakuRy3/JCUjetkpH1EzE=
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=pfera.local
## THESE ARE DB CREDS THAT ARE SPECIFIC TO YOUR OWN DATABASE
## REAL PASSWORD REMOVED FOR PLAIN TEXT TRANSFER
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD=password
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
## REAL MAILGUN SECRET REMOVED FOR PLAINT TEXT TRANSFER
## THIS IS FOR CODE AND MORTAR'S DEVELOPMENT ACCOUNT, UNIQUE CREDENTIALS WILL
## NEED TO BE CREATED FROM YOUR OWN ACCOUNT FOR PRODUCTION, LOCAL DEVELOPMENT,
## AND ONCE THE STAGING ENVIRONMENT IS FULLY TRANSITIONED
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=mg.codeandmortar.com
MAILGUN_SECRET=12345678
MAIL_FROM_NAME="Pfera"
MAIL_FROM_ADDRESS="no-reply@pfera.ca"
MAIL_FROM="no-reply@pfera.ca"
## THESE ARE ALL VARIABLES FOR SPARK FEATURES NOT IMPLEMENTED IN THIS PHASE
PUSHER_KEY=
PUSHER_SECRET=
PUSHER_APP_ID=
AUTHY_SECRET=
STRIPE_MODEL=App\User
STRIPE_KEY=
STRIPE_SECRET=
BRAINTREE_MODEL=App\User
BRAINTREE_ENV=
BRAINTREE_MERCHANT_ID=
BRAINTREE_KEY=
BRAINTREE_SECRET=
## END NON-IMPLEMENTED SPARK VARIABLES
## PAGINATION
HORSES_PER_PAGE=20
EVENTS_PER_PAGE=20
TESTS_PER_PAGE=20
USERS_PER_PAGE=20
## ESTIMATED ESTROUS CYCLE LENGTH IN DAYS
ESTROUS_CYCLE=21
## VARIABLES THE POINT OUT:
## 1) THE PATH TO THE `Rscript` EXECUTABLE TO RUN R CODE
## 2) THE PATH TO THE R CODE REPO
## 3) THE FILENAME OF THE R CODE TO RUN
## NOTE THAT ON THE SERVER WE'RE USING `chroot` SINCE THE R AND PHP UBUNTU
## BINARIES HAD CONFLICTING DEPENDENCIES, THIS IS WHY THE "RELATIVE" PATH FOR
## THE R SCRIPT IS JUST `.`, BECAUSE IT IS WITHIN THE ROOT OF THE CHROOT JAIL.
## THIS WILL ALMOST DEFINITELY NOT BE THE CASE IN LOCAL DEVELOPMENT. FOR LOCAL
## DEVELOPMENT, I WOULD STRONGLY RECOMMEND PROVING `R_PREDICT_PATH` A FULL PATH
## TO THE DIRECTORY THAT CONTAINS THE R CODE (THIS PATH MUST NOT INCLUDE THE R
## FILE ITSELF)
RSCRIPT_BIN="chroot /var/chroot Rscript"
R_PREDICT_PATH=/c/Users/Aslam/Desktop/Pfera_application/pfera-r
R_PREDICT_FILE=predict.R
【问题讨论】:
请附上你的database.php文件 .env 文件已正确安装我已检查 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret 【参考方案1】:如果您确定您的数据库用户和密码,这是一个连接错误,然后尝试在 cli 中退出您的 artisan 服务器并重新运行
php artisan serve
如果您不确定您的用户名或密码,并且您正在使用带有 vagrant 的宅基地
试试下面的
DB_DATABASE=forge
DB_USERNAME=homestead
DB_PASSWORD=secret
如果您不确定自己的密码和用户名,并且不使用 vagrant homestead
试试这个
DB_DATABASE=forge
DB_USERNAME=root
DB_PASSWORD=
【讨论】:
【参考方案2】:Laravel 仍在尝试使用默认的 Forge 配置。您需要打开 .env
和 config/database.php
文件并配置 MySQL 的连接信息。
您的config/database.php
文件很可能已经为MySQL 配置了,所以我将主要介绍您的.env
文件。 .env
文件存在,因此您可以为您的开发和生产环境定义不同的选项。
在您的 .env
文件中,像这样配置它:
DB_CONNECTION=mysql
DB_TEST_DATABASE=database_name
DB_TEST_USERNAME=mysql_user_with_access_to_the_database
DB_TEST_PASSWORD=your_super_secure_password
默认情况下,config/database.php
文件设置为从您的 .env
文件中提取此信息。如果.env
文件不存在,则它有自己的备用信息。
【讨论】:
我的 .env 就是这样设置的。【参考方案3】:你的 laravel .env
与 DB 的错误相关配置
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
【讨论】:
我再次编辑了帖子,并包含了 php 数据库文件和 .env 文件。 你在连接mysql吗? @JennyYu 是的,这就是我想要做的。但不幸的是有错误...... 创建新数据库并将其与 laravel 连接,然后发出命令:php artisan migrate
@JennyYu【参考方案4】:
数据库连接数据在 config/database.php 文件中定义,mysql 行是这样的:
'host' => env('DB_HOST', 'localhost'),
第一个参数表示从 .env 文件中获取此值,并且出于任何原因,如果它无法加载该信息,请使用第二个参数。 所以你应该在这两个文件中定义你的凭据。
如果没有任何帮助,请使用
'host' => 'localhost',
对应数据库配置行的每一行
【讨论】:
唯一改变的是“SQLSTATE[HY000] [2054] 服务器请求客户端未知的身份验证方法(SQL:select * from information_schema.tables where table_schema = forge and table_name = migrations)” 【参考方案5】:也许,如果您的 MySQL 密码包含此字符 #
,您必须在密码值中添加引号。因为 env 文件读取 #
字符作为注释而不是字符串字符。但是,如果您在 env 值中添加引号 ""
,则 env 文件可以将 #
字符读取为字符串文本而不是注释
例子:
DB_PASSWORD="some-secret-password#"
【讨论】:
请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。 感谢您的建议,我已经编辑了我的答案以上是关于Artisan Migrate 访问被拒绝的主要内容,如果未能解决你的问题,请参考以下文章
远程 AWS EB 实例上的“php artisan migrate”上的 PHP 致命错误:laravel.log:权限被拒绝
php artisan migrate 不适用于 Laravel 5.4 中的 XAMPP