Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote mysql database on Heroku app

Can I use mysql database from my personal web server instead of heroku's database?

I configured my production database like this:

production:     adapter: mysql2     database: somedatabase     username: someusername     password: somepassword     host: 1.1.1.1:1234 

But, this doesn't work, my app still uses heroku's shared database.

like image 893
dormitkon Avatar asked Mar 22 '11 19:03

dormitkon


People also ask

Can we use MySQL database in Heroku?

Existing ClearDB shared MySQL customers can now run heroku addons:upgrade to upgrade existing ClearDB shared MySQL add-ons to dedicated ClearDB MySQL add-ons.

Is ClearDB free on Heroku?

Starting at $0/mo.

Does heroku have PHPMyAdmin?

We have deployed a PHP project to Heroku, made a remote MySQL database, configured the database using PHPMyAdmin, and finally connected our app to the database.


2 Answers

This is old but in case anyone drops around looking for an answer, it's much easier than using the gem. Just provide a DATABASE_URL and SHARED_DATABASE_URL (not sure if the second is needed). The database url format is adapter://username:password@hostname:port/database, so for example, you would do:

heroku config:add DATABASE_URL=mysql://etok:somepassword@<your-server>:3306/etok heroku config:add SHARED_DATABASE_URL=mysql://etok:[email protected]:3306/etok 

Then re-deploy your app. It will read your DATABASE_URL and generate the database.yml from that. The default port is already 3306 so it's not needed in the url in your case. When you deploy, you may notice that it generates your database.yml:

-----> Writing config/database.yml to read from DATABASE_URL 

Then you're set (as long as your server accepts connections from your heroku host.

like image 114
Vince Avatar answered Oct 05 '22 15:10

Vince


I've written a gem that may help with this. You can find it at:

http://github.com/nbudin/heroku_external_db

like image 21
Nat Budin Avatar answered Oct 05 '22 16:10

Nat Budin