0

首先,我们可以使用以下命令访问 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。

我也尝试通过使用本地主机 IP 创建用户。

创建由''标识的用户'ck'@'172.31.29.230';

但这也没有用。

我也参考了这篇文章:

java.sql.SQLException:用户拒绝访问

关于此数据库连接问题,是否还有其他建议或我可能遗漏的其他内容?谢谢。

4

1 回答 1

1

When you grant access on RDS, you grant access to the host you are connecting from, not the host you are connecting to. Being that private IPs usually change within ec2, its best to use the security group to control access and set grants with a wildcard host %

于 2013-09-23T14:11:54.943 回答