Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy local MySQL database to Heroku

Tags:

mysql

heroku

I'm new to using Heroku and I have a Ruby/Sinatra app in which I plan on using a MySQL database as the main data store.

However, I do not want to write results directly to the database on Heroku. Instead, I want to write the results to a local database, and then be able to easily deploy/update/copy my local DB to the "production" database on Heroku.

How do I do this?

Thanks.

like image 966
Ken Avatar asked Mar 03 '13 21:03

Ken


People also ask

Can I host MySQL database in Heroku?

Heroku does not offer a native MySQL add-on but instead supplies it through a third party, ClearDB. If it has not been added to your application already, you can install it from the Heroku Add-Ons Page. Once installed, it will appear in your Add-Ons list in your Resources tab as ClearDB MySQL .

Is Heroku MySQL free?

The high speed database for your MySQL powered applications. Starting at $0/mo.


2 Answers

Firstly Heroku natively uses postgres. Life will be easier for you if you use that locally.

You can import / export postgres dump files from heroku as described here: https://devcenter.heroku.com/articles/heroku-postgres-import-export

If you really want to use mysql, you have two paths to follow.

1) Run mysql locally, but convert to postgres when migrating to Heroku using the mysql2psql gem, as described here: https://devcenter.heroku.com/articles/heroku-mysql

2) Use a mysql addon like https://addons.heroku.com/cleardb

However my recommendation would be to use postgres end to end, as it is baked into Heroku, and you'll be working with the default ways of using Heroku, not against them.

Postgres is very good too!

like image 68
DanSingerman Avatar answered Nov 07 '22 14:11

DanSingerman


I know nothing about Ruby & Sinatra, so feel free to comment and let me know how wrong I am if that's the case. However, I thought it might be pertinent to mention the JawsDB Plugin on Heroku, as the top answer here is from 2013 and may be a bit outdated.

Here is a link with info on the JawsDB plugin: https://devcenter.heroku.com/articles/jawsdb

Provisioning the plugin is as simple as running the following command in the CLI:

heroku addons:create jawsdb 

Then configure the host, username, password, & database with parameters from MySQL Workbench (or whatever GUI you use).

like image 39
Billeh Avatar answered Nov 07 '22 13:11

Billeh