我知道这个问题有很多类似的问题,但没有一个能帮助我解决这个问题。
我正在尝试将我的 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@% |
+------------------------+----------------+
HUX布斯
胡子哥哥