猿问

SQLSTATE[HY000] [1045] 用户 'username'@

我知道这个问题有很多类似的问题,但没有一个能帮助我解决这个问题。


我正在尝试将我的 EC2 实例上的 laravel 项目连接到我的 RDS 实例。


我可以成功连接到 RDS 实例并在我使用时创建表:


mysql -h ....rds.amazonaws.com -u cmadmin -p

但是,我目前在运行时遇到以下错误php artisan migrate:


In Connection.php line 664:


  SQLSTATE[HY000] [1045] Access denied for user 'cmadmin'@'ec2_privateIP' (using password: YES) (SQL: select * from information_schema.tables where table_schema = dbname_cm and table_name = migrations)



In Connector.php line 67:


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

这是 .env 文件的摘录:


APP_NAME=Laravel

APP_ENV=local

APP_KEY=generatedkey

APP_DEBUG=true

APP_LOG_LEVEL=debug

APP_URL=http://localhost


DB_CONNECTION=mysql

DB_HOST=....rds.amazonaws.com

DB_PORT=3306

DB_DATABASE=dbname_cm

DB_USERNAME=cmadmin

DB_PASSWORD=rfL8zvXnMEzit02

这是 config/database.php 文件的摘录:


'mysql' => [

    'driver' => 'mysql',

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

    'port' => env('DB_PORT', '3306'),

    'database' => env('DB_DATABASE', ''),

    'username' => env('DB_USERNAME', ''),

    'password' => env('DB_PASSWORD', ''),

    'unix_socket' => env('DB_SOCKET', ''),

    'charset' => 'utf8mb4',

    'collation' => 'utf8mb4_0900_ai_ci',

    'prefix' => '',

    'strict' => false,

    'engine' => null,

    'option'  => [

        PDO::MYSQL_ATTR_SSL_CA => base_path('/var/mysql-cert/dbname_cm-db.pem')

    ],

],

我什至将以下内容添加到app/Providers/AppServiceProvider.php


public function boot()

    {

       Schema::defaultStringLength(191);

    }

我已经运行了: php artisan cache:clear php artisan config:clear php artisan config:cache


PHP 7.2.24-0ubuntu0.18.04.4 Laravel 框架 5.5.49 AWS RDS:MySQL 8.0.17


mysql> SELECT USER(),CURRENT_USER();

+------------------------+----------------+

| USER()                 | CURRENT_USER() |

+------------------------+----------------+

| cmadmin@ec2_privateIP  | cmadmin@%      |

+------------------------+----------------+



缥缈止盈
浏览 227回答 2
2回答

HUX布斯

    'driver' => 'mysql',    'host' => env('DB_HOST', ''),    'port' => env('DB_PORT', '3306'),    'database' => env('DB_DATABASE', ''),    'username' => env('DB_USERNAME', ''),    'password' => env('DB_PASSWORD', ''),    'unix_socket' => env('DB_SOCKET', ''),    'charset' => 'utf8mb4',    'collation' => 'utf8mb4_0900_ai_ci',    'prefix' => '',    'strict' => false,    'engine' => null,    'option'  => [        PDO::MYSQL_ATTR_SSL_CA => base_path('/var/mysql-cert/dbname_cm-db.pem')    ],],```have you already try file this part `'username' => env('DB_USERNAME', ''),` with `'username' => env('DB_USERNAME', 'cmadmin'),`and of course the DB_PASSWORD part with your predefined password

胡子哥哥

我通过在 database.php 文件中添加以下代码解决了这个问题'mysql' = ['sslmode' => 'require','options'   => array(            PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,            PDO::MYSQL_ATTR_SSL_KEY => '/certs/client-key.pem',            PDO::MYSQL_ATTR_SSL_CERT => '/certs/client-cert.pem',            PDO::MYSQL_ATTR_SSL_CA => '/certs/ca.pem',        )],
随时随地看视频慕课网APP
我要回答