简体   繁体   中英

Amazon RDS Unknown MYSQL Host

I've been trying to connect to an RDS database from an application I'm hosting on elastic beanstalk. It gives me this error:

[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.

The server host is the correct hostname of the database, I just x'd it out.
I am able to connect to and view this database via the MYSQL workbench but not on localhost or AWS. I've tried putting the host in manually rather than using a variable but that gave me the same error

Here is where I try to connect in my database.yml file

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'] %>

I've also tried messing around with the security groups but nothing really changes

When I try to connect on localhost it gives me

MYSQL2 Error Can't connect to MySQL server on 'localhost' (10061)

The above issue is due to your EC2 instance is not having access to your MYSQL RDS. Please add the access and your app will start working. Please follow this guide http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithSecurityGroups.html#USER_WorkingWithSecurityGroups.AuthorizingEC2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM