13

How to deploy a Rails app using Mysql on heroku?

I find out that my app did not need Amazon RDS (Too expensive for a small app).

Here is my answer how to use Amazon RDS

Heroku help deploying Rails app that uses Mysql database

6
  • This user very recently asked the same question: Heroku help deploying Rails app that uses Mysql database Commented Mar 19, 2011 at 15:12
  • Yes I have tried. I have pushed my app to heroku and added Amazon RDS. But I cant connect to the database. See my steps here stackoverflow.com/questions/5362288/… Commented Mar 19, 2011 at 15:12
  • heroku.com - create -> deploy -> work -- everything is written there, no? Commented Mar 19, 2011 at 15:17
  • no. Should I use Amazon RDS for a Mysql database? Commented Mar 19, 2011 at 15:20
  • Heroku uses PostgreSQL I need to use MySql because I have much of MySql data I need to push Commented Mar 19, 2011 at 15:27

2 Answers 2

22

Include mysql2 gem in your gemfile:

gem 'mysql2'

Now, your choice can be: https://addons.heroku.com/cleardb add-ons. You can get upto 5mb free storage but you need to fill your credit card information for accessing it.

Steps for using clearDB add-ons are:

# add cleardb add-ons to your app
$ heroku addons:add cleardb:ignite
-----> Adding cleardb to sharp-mountain-4005... done, v18 (free)


# retrieve your database URL:
$ heroku config | grep CLEARDB_DATABASE_URL
CLEARDB_DATABASE_URL => mysql://adffdadf2341:[email protected]/heroku_db?reconnect=true


# copy CLEARDB_DATABASE_URL config variable and set it to your DATABASE_URL config variable
$ heroku config:set DATABASE_URL='mysql://adffdadf2341:[email protected]/heroku_db?reconnect=true'
Adding config vars:
DATABASE_URL => mysql2://adffd...b?reconnect=true
Restarting app... done, v61.

# NOTE: since we are using ```mysql2``` in our gemfile so replace mysql:// scheme in the CLEARDB_DATABASE_URL to mysql2://
$ heroku config:set DATABASE_URL='mysql2://adffdadf2341:[email protected]/heroku_db?reconnect=true'
$ heroku config:set CLEARDB_DATABASE_URL='mysql2://adffdadf2341:[email protected]/heroku_db?reconnect=true'

Please follow: https://devcenter.heroku.com/articles/cleardb for more information

Hope that can help you.

Sign up to request clarification or add additional context in comments.

Comments

9

If you do a heroku db:push from your MySql data, it'll automatically get pushed into the heorku PostgreSQL database structure.

You can then do db:pulls and pull back into mysql. Taps provides this database magic.

It's really great -- I'd try it out first before trying to get RDS working.

3 Comments

I have got the RDS to work and have pushed my database to RDS. But my app still crashes here is my log pastie.org/1690168
This answer may need to be updated. Running heroku db:push gives the error db:push is not a heroku command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.