无法使用Lumen框架连接到mysql表

问题描述 投票:0回答:1

背景:我使用brew安装php7.2,然后使用brew安装mysql。适用于x86_64(自制)上osx10.14的mysql Ver 8.0.19。然后使用作曲家创建我的流明项目composer create-project --prefer-dist laravel/lumen blog

我正在尝试将数据插入到我的表中,并在邮递员中引发错误SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost'

这是我的.env文件

APP_NAME=Lumen
APP_ENV=local
APP_KEY= 9887765535434424354566gfr547633
APP_DEBUG=true
APP_URL=http://localhost
APP_TIMEZONE=UTC

LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=pqueue
DB_PASSWORD=password
DB_STRICT_MODE=false
DB_SOCKET=/tmp/mysql.sock

CACHE_DRIVER=array
QUEUE_DRIVER=database

在我的配置> database.php中,我具有默认设置

返回[

'default' => env('DB_CONNECTION', 'mysql'),


'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => env('DB_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' => env('DB_CHARSET', 'utf8mb4'),
        'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
        'prefix' => env('DB_PREFIX', ''),
        'strict' => env('DB_STRICT_MODE', true),
        'engine' => env('DB_ENGINE', null),
        'timezone' => env('DB_TIMEZONE', '+00:00'),
    ],

    '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' => env('DB_CHARSET', 'utf8'),
        'prefix' => env('DB_PREFIX', ''),
        'schema' => env('DB_SCHEMA', 'public'),
        'sslmode' => env('DB_SSL_MODE', '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' => env('DB_CHARSET', 'utf8'),
        'prefix' => env('DB_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',

    'cluster' => env('REDIS_CLUSTER', false),

    'default' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => env('REDIS_DB', 0),
    ],

    'cache' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => env('REDIS_CACHE_DB', 1),
    ],

],

];`

我不确定可能是什么问题。

当我运行php artisan migrate:refreshphp artisan migrate --env=production时>>

In Connection.php line 664:

  SQLSTATE[HY000] [1045] Access denied for user 'pqueue'@'localhost' (using password: YES) (SQL: select * from information_schema.ta
  bles where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')


In Connector.php line 70:

  SQLSTATE[HY000] [1045] Access denied for user 'pqueue'@'localhost' (using password: YES)

但是我已经授予了对测试数据库中所有表的授予访问权限GRANT ALL on test.* to pqueue@localhost;

我能够使用pqueue凭据创建表,并通过使用mysql控制台在测试数据库中插入数据。所以我知道用户有足够的前置权。

有人可以帮我调试吗?

背景:我使用brew安装php7.2,然后使用brew安装mysql。适用于x86_64(自制)上osx10.14的mysql Ver 8.0.19。然后使用composer composer create-project创建了我的流明项目--...

php mysql laravel lumen
1个回答
0
投票

我已经解决了我的问题。如果其他人也遇到类似的问题,请确保您的mysql用户的密码中没有“#”。

© www.soinside.com 2019 - 2024. All rights reserved.