Connect MySQL RDS to a Rails application

suggest change

Create the MySQL database

  1. Sign in to AWS and open the RDS service.
  2. Choose Launch DB Instance.
  3. MySQL Community Edition is selected by default. Click Select.
  4. Choose the use case, for example production, and click Next.
  5. Set the MySQL version, storage size, DB instance identifier, master username, and password, then click Next.
  6. Enter the database name and click Launch DB Instance.
  7. Wait until the instance is available. Copy the endpoint. That value is the hostname.

Install the adapter

Add the MySQL adapter to the Gemfile:

gem 'mysql2'

Then run bundle install.

Other adapters:

Configure config/database.yml

<%= RDS_DB_NAME %> is not an environment variable. Read the values from ENV:

production:
  adapter: mysql2
  encoding: utf8
  database: <%= ENV["RDS_DB_NAME"] %>   # name set when creating the database
  username: <%= ENV["RDS_USERNAME"] %>  # master username
  password: <%= ENV["RDS_PASSWORD"] %>  # master password
  host: <%= ENV["RDS_HOSTNAME"] %>      # instance endpoint
  port: <%= ENV["RDS_PORT"] %>          # MySQL default is 3306

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents