Amazon RDS未知MYSQL主机

时间:2016-06-08 19:02:17

标签: mysql ruby-on-rails amazon-web-services

我一直在尝试从我在弹性beanstalk上托管的应用程序连接到RDS数据库。它给了我这个错误:

[Instance: i-0f0051f7599e17190] Command failed on instance. Return code: 1 
Output: (TRUNCATED)... -s /bin/bash -c 'leader_only bundle exec rake 
db:migrate' webapp rake aborted! Mysql2::Error: Unknown MySQL server host 
'xxxxxxxxxx.xxxxxxxxx.us-west-2.rds.amazonaws.com' (25) Tasks: TOP => 
 db:migrate (See full trace by running task with --trace). Hook 
/opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh failed. For 
more detail, check /var/log/eb-activity.log using console or EB CLI.

服务器主机是数据库的正确主机名,我只是x了 我可以通过MYSQL工作台连接并查看此数据库,但不能在localhost或AWS上连接和查看。我已尝试手动放置主机而不是使用变量,但这给了我同样的错误

这是我尝试在我的database.yml文件中连接的地方

production:
  adapter: mysql2
  encoding: utf8
  database: <%= ENV['RDS_DB_NAME'] %>
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>

我也试过搞乱安全组但没有真正改变

当我尝试连接localhost时,它会给我

MYSQL2错误 无法在&#39; localhost&#39;上连接到MySQL服务器(10061)

1 个答案:

答案 0 :(得分:0)

上述问题是由于您的EC2实例无法访问您的MYSQL RDS。请添加访问权限,您的应用将开始工作。请按照本指南http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithSecurityGroups.html#USER_WorkingWithSecurityGroups.AuthorizingEC2

进行操作