How do I connect my Rails app to use MySQL on my digital Ocean droplet?

Hi, my Ruby on Rails demo app runs well with Sqlite. I now need to use MySQL database created on my droplet. Ho would I do this. I would appreciate your support Pierre


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Generally, in order to use MySql for a Rails app there are a few steps that need to be followed. First, install MySql itself:

sudo apt-get install mysql-server

You’ll also want to create a separate user and database for your app. This tutorial will walk you through creating users in MySql:

Next, require the mysql gem in your app’s Gemfile and re-run bundle install in order to install it.

Then in your config/database.yml file, you’ll need to set the correct information for your app to be able to connect to the database. It would look something like this:

  adapter: mysql
  encoding: utf8
  database: rails_app
  username: rails_user
  password: pwd
  port: 3306
  pool: 10

Hopefully, this points you in the right direction. Let us know how it goes!