嗨,我正在尝试连接到RDS数据库,但遇到此错误:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from information_schema.tables where table_schema = ebdb and table_name = migrations)
at /var/app/current/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|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] Connection timed out")
/var/app/current/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
2 PDO::__construct("mysql:host=[RDS host]", "[RDS user]", "[RDS PASS]", [])
/var/app/current/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
Please use the argument -v to see more details.
我正在config / database.php中使用此代码
这就是我声明常量的方式
define('RDS_HOST',$_SERVER['RDS_HOSTNAME']);
define('RDS_USER',$_SERVER['RDS_USERNAME']);
define('RDS_PASS', $_SERVER['RDS_PASSWORD']);
define('RDS_DB_NAME',$_SERVER['RDS_DB_NAME']);
define('RDS_PORT',$_SERVER['RDS_PORT']);
这是数据库连接代码:
'mysql' => [
'driver' => 'mysql',
'host' => RDS_HOST,# env('DB_HOST', '127.0.0.1'),
'port' => RDS_PORT, #env('DB_PORT', '3306'),
'database' => RDS_DB_NAME, # env('DB_DATABASE', 'forge'),
'username' => RDS_USER,# env('DB_USERNAME', 'forge'),
'password' => RDS_PASS, # env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
]