在AWS RDS Console中修改RDS实例,进入“connectivity”选项卡,启用“SSL”选项。
在代码中,需要在连接URL中添加SSL选项: jdbc:mysql://rds_endpoint:port/dbname?verifyServerCertificate=true&useSSL=true&requireSSL=true
其中,rds_endpoint是RDS实例的终端节点,port是RDS实例的端口号,dbname是要连接的数据库名。verifyServerCertificate=true表示需要验证服务器SSL证书,useSSL=true表示连接时启用SSL,requireSSL=true表示SSL连接是必需的。
Java代码示例:
Properties props = new Properties(); props.setProperty("user", "username"); props.setProperty("password", "password"); props.setProperty("verifyServerCertificate", "true"); props.setProperty("useSSL", "true"); props.setProperty("requireSSL", "true");
String url = "jdbc:mysql://rds_endpoint:port/dbname"; Connection conn = DriverManager.getConnection(url, props);