artisan迁移访问被拒绝

egmofgnx  于 2021-06-23  发布在  Mysql
关注(0)|答案(4)|浏览(380)

我在建立一个拉威尔的环境。因此,我下载了xampp并相应地配置了vhost文件。然后,我设置mysql并运行以下命令:
编写器安装
npm安装
php artisan(确认我有artisan)
php artisan迁移
在运行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
axr492tv

axr492tv1#

数据库连接datail在config/database.php文件中定义,mysql行如下所示:

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

其中第一个参数表示从.env文件中获取该值,如果由于任何原因无法加载该信息,请使用第二个参数。所以你应该在这两个文件中定义你的凭证。
如果没有任何帮助

'host' => 'localhost',

对应于数据库配置行的每一行

cczfrluj

cczfrluj2#

如果确定数据库用户和密码,然后尝试在cli中退出artisan服务器并重新运行,则这是一个连接错误

php artisan serve

如果你不确定你的用户名或密码,你正在使用与流浪者家园
请尝试以下操作

DB_DATABASE=forge
DB_USERNAME=homestead
DB_PASSWORD=secret

如果你不确定你的密码和用户名,不使用流浪宅基地
试试这个

DB_DATABASE=forge
DB_USERNAME=root
DB_PASSWORD=
klsxnrf1

klsxnrf13#

你的错误相关配置的拉威尔 .env 含db DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret

jgovgodb

jgovgodb4#

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 文件不存在,它有自己的回退信息。

相关问题