首先,我们可以使用以下命令访问RDS / MySQL数据库:
mysql -h ckinstance.cx2ecc4osrgp.us-west-2.rds.amazonaws.com -P 3306 -u ck -p<PASSWORD>
然后,我们尝试添加root用户和密码,以通过以下方式提供对RDS / MySQL数据库的访问:
create user 'ck'@'ckinstance.cx2ecc4osrgp.us-west-2.rds.amazonaws.com' identified by '<PASSWORD>';
grant all privileges ck.* to 'ck'@'ckinstance.cx2ecc4osrgp.us-west-2.rds.amazonaws.com';
我们的webapp属性文件包含:
com.careerkick.jpa.url=jdbc:mysql://ckinstance.cx2ecc4osrgp.us-west-2.rds.amazonaws.com:3306/ck
com.careerkick.jpa.username=ck
com.careerkick.jpa.password=<password>
然而,当我们运行我们的webapp时,日志显示它仍然试图通过localhost访问它:
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0
com.mchange.v2.resourcepool.BasicResourcePool -
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6c3bae8 -- Acquisition
Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new
resource, we failed to succeed more than the maximum number of allowed acquisition
attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Access denied for user 'ck'@'172.31.29.230' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:927)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1709)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1252)
出于某种原因,它似乎想要使用localhost IP。
我也尝试过使用localhost IP创建用户。
创建用户'ck'@'172.31.29.230'由'';
标识但这也不起作用。
我也用这篇文章作为参考:
java.sql.SQLException: Access denied for user
对于此数据库连接问题,是否还有其他建议或者我可能缺少其他内容?感谢。
答案 0 :(得分:1)
在RDS上授予访问权限时,您可以授予对要连接的主机的访问权限,而不是您要连接的主机。由于私有IP通常在ec2内发生变化,因此最好使用安全组来控制访问并使用通配符主机设置授权%