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

Community
  • 1
  • 1
Rails beginner
  • 14,321
  • 35
  • 137
  • 257
  • This user very recently asked the same question: [Heroku help deploying Rails app that uses Mysql database](http://stackoverflow.com/questions/5362288/heroku-help-deploying-rails-app-that-uses-mysql-database) – Andrew Marshall Mar 19 '11 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 http://stackoverflow.com/questions/5362288/heroku-help-deploying-rails-app-that-uses-mysql-database – Rails beginner Mar 19 '11 at 15:12
  • http://heroku.com/ - create -> deploy -> work -- everything is written there, no? – Sergey Kishenin Mar 19 '11 at 15:17
  • no. Should I use Amazon RDS for a Mysql database? – Rails beginner Mar 19 '11 at 15:20
  • Heroku uses PostgreSQL I need to use MySql because I have much of MySql data I need to push – Rails beginner Mar 19 '11 at 15:27
  • I get the same error as http://stackoverflow.com/questions/3969272/trouble-connecting-heroku-app-with-amazon-rds-instance – Rails beginner Mar 19 '11 at 17:26

2 Answers2

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:adf4234@us-cdbr-east.cleardb.com/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:adf4234@us-cdbr-east.cleardb.com/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:adf4234@us-cdbr-east.cleardb.com/heroku_db?reconnect=true'
$ heroku config:set CLEARDB_DATABASE_URL='mysql2://adffdadf2341:adf4234@us-cdbr-east.cleardb.com/heroku_db?reconnect=true'

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

Hope that can help you.

przbadu
  • 5,769
  • 5
  • 42
  • 67
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.

Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • I have got the RDS to work and have pushed my database to RDS. But my app still crashes here is my log http://pastie.org/1690168 – Rails beginner Mar 19 '11 at 18:26
  • My answer http://stackoverflow.com/questions/5362288/heroku-help-deploying-rails-app-that-uses-mysql-database – Rails beginner Mar 19 '11 at 19:35
  • 1
    This answer may need to be updated. Running `heroku db:push` gives the error `db:push is not a heroku command.` – Dennis Mar 17 '14 at 20:19