我已按照Heroku的建议授予了Amazon RDS MySQL实例(5.7.19)0.0.0.0/0的访问权限。这使连接成功。当我为mysql用户强制使用SSL时(ALTER USER'用户'@'%'REQUIRE SSL;)连接断开。我跟随了Heroku的these instructions。
我的Heroku DATABASE_URL配置变量:mysql://用户名:密码@ AMAZONRDSMYSQLURL / DATABASE?sslca = config / amazon-rds-ca-cert.pem
证书存储在/config/amazon-rds-ca-cert.pem下
从我的localhost终端,我可以使用此命令通过SSL连接到Amazon RDS实例(使用相同的证书)(也可以不使用--ssl-mode = VERIFY_IDENTITY):mysql -h AMAZONRDSMYSQLURL --ssl-ca = / Users /Documents/amazon-rds-ca-cert.pem --ssl-mode = VERIFY_IDENTITY -u USERNAME -p
我在Lumen中的数据库配置(/config/database.php):
<?php
$url = parse_url(getenv("DATABASE_URL"));
$host = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$database = substr($url["path"], 1);
return [
'default' => 'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'port' => '3306',
'host' => $host,
'database' => $database,
'username' => $username,
'password' => $password,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
有什么想法在这里出错吗?谢谢!
您尚未告知数据库文件使用SSL。
<?php
$url = parse_url(getenv("DATABASE_URL"));
$host = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$database = substr($url["path"], 1);
return [
'default' => 'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'port' => '3306',
'host' => $host,
'database' => $database,
'username' => $username,
'password' => $password,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'options' => array(
"sslmode" => "require",
"sslrootcert" => "config/amazon-rds-ca-cert.pem"
)
],
我终于使用了:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'port' => '3306',
'host' => $host,
'database' => $database,
'username' => $username,
'password' => $password,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'options' => array(
PDO::MYSQL_ATTR_SSL_CA => '../config/amazon-rds-ca-cert.pem'
)
],