How to configure mysql2 database in heroku - heroku

I am using mysql database in my rails application, my development database is mysql2. I want to set mysql2 database in heroku. how to configure mysql2 database in heroku?

Heroku uses Postgres by default, so it is recommended to set your production database to Postgres.
If you really want to stick to mysql your could either use the mysql2postgres gem to translate your mysql database to postgres or you can use addons:
https://addons.heroku.com/#data-stores
In your case you could use ClearDB MySql database. It does require more effort than using the default Postgres database though, but this guide might help:
https://devcenter.heroku.com/articles/cleardb

Retrieve your database URL by issuing the following command:
$ heroku config | grep CLEARDB_DATABASE_URL
CLEARDB_DATABASE_URL => mysql://adffdadf2341:adf4234#us-cdbr-east.cleardb.com/heroku_db?reconnect=true
then copy the value of the CLEARDB_DATABASE_URL config variable.
$ heroku config:set DATABASE_URL='mysql://adffdadf2341:adf4234#us-cdbr-east.cleardb.com/heroku_db?reconnect=true'
from here:
https://devcenter.heroku.com/articles/cleardb

Related

heroku pg:pull from database's on Amazon

I having being trying to run pg:pull from my Heroku app which one has a database on Amazon RDS, but the commands keep returning 'app-name has no databases' even if I use the database url set on my Config Vars .. Am I missing something ?
try ...
heroku pg:pull DATABASE_URL local_database_name --remote app_name
return ...
app_name has no databases
heroku pg:pull is not compatible with databases that aren't hosted on the plaform. This is specified in the documentation:
pg:pull can be used to pull remote data from a Heroku Postgres database to a database on your local machine. The command looks like this:
You will need to run pg_dump and a subsequent pg_restore manually to achieve the same result as the automated pg:pull command.

heroku rake db:structure:load failure

I need to use some PostgreSQL proprietary features such as rules and triggers for table partitioning. As long as I know, these kind of features cannot be dump to schema.rb so I have changed my schema_format configuration parameter to :sql.
Now, when I try to load rake db:structure:load to load the generated structure.sql into the heroku database, it fails saying: sh: psql: not found
How can I do it?
You can use pg:psql to run the script from your development machine against the database:
cd your-rails-project
heroku pg:psql -a your-app-name <db/structure.sql
Just make sure that the branch you have checked out locally is the same as the one you have deployed.

Heroku, data import error with mysql2

I am beginner on Heroku.
I push my exist ruby on rails application into heroku and that was fine.
Next i push my mysql data into heroku with 'push' command as following.
$heroku config:add DATABASE_URL='mysql2://<my CLEARDB_DATABASE_URL>#<myapp>.herokuapp.com/heroku_db?reconnect=true'
$heroku db:push mysql2://<my CLEARDB_DATABASE_URL>#<myapp>.herokuapp.com/<my dump file>
But i got error as following.
Failed to connect to database:
Sequel::DatabaseConnectionError -> Mysql2::Error: Can't connect to MySQL server on '<myapp>.herokuapp.com' (110)
I am confusing what should i do.
Someone tell me how to resolve it.
Many thanks.
-Ono
Don't use db:push or db:pull. Please export a sql file locally and either pipe it in like so:
$ heroku pg:psql DATABASE_URL -a app_name < file.sql
Or better, use Postgres locally and use pgbackups to import/export like so: Importing and Exporting Heroku Postgres Databases with PG Backups

No such file 'config/database.yml' on Heroku

My app is a Ruby rack app. When my Heroku app starts it breaks because
/app/config.ru:8:in `read': No such file or directory - config/database.yml (Errno::ENOENT)
Why does this happen? I understood Heroku is meant to create this file https://devcenter.heroku.com/articles/cedar-migration
The database credentials will still be configured automatically: at slug compile time, a config/database.yml that parses the DATABASE_URL from the environment will be written into the app.
Frustratingly the doc at https://devcenter.heroku.com/articles/ruby doesn't explain about database.yml
Ok, the first thing - heroku does not use database.yml file. By default rails app loading it from config/ directory automatically. And it's no need to load it manually in config.ru. If you want to use in heroku PosgreSQL - just add add-on. Heroku wil do all other things to link your app and db. If you want to use external MySQL server you should use Amazon RDS add-on
heroku addons:add amazon_rds url=mysql2://user:pass#dbhost/dbname
By this you can use any db. I use GoDaddy mysql bases through the Amazon RDS add-on.
Any way, the problem in your config.ru 8th line something like
read 'config/database.yml'
Delete it and look other ways that not conflicted with heroku
Good luck
It appears Heroku only creates its config/database.yml if you have a folder config under source control. Not explained in docs.

Heroku app change: db migration (pg and MongoHQ)

I had and app on heroku
then I decided to create another app (on cedar stack which does not support stack:migrate).
How can I migrate databases PG and MongoHq?
Thanks!
You can migrate MongoHQ by logging into heroku and clicking on addons => mongohq. From the application, create a new user under Database Users named "backup" with a simple password. Below, my password was "temppw". Then click the Database Info tab for your connection information (host:port [flame.mongohq.com:27049] and dbname [appXXXXXX]). Then just call mongodump to get a backup.
mongodump -h flame.mongohq.com:27049 -d appXXXXXX -u backup -p temppw
This will make a local directory called "dump" containing your data. Verify it is there by loading it into a local db (just run mongorestore and look in your local mongo install) - because when you destroy your old app, it destroys the MongoDB (heroku also destroys your postgres db - so you should do this for that as well).
Anyway, do the same as above to your new application database, except use mongorestore.
mongorestore -h flame.mongohq.com:27049 -d appXXXXXX -u backup -p temppw dump/appXXXXXX
DO NOT JUST POINT THE ENVIRONMENT URLS. This is dangerous, because deleting your initial app will destroy all of your data.
I'm not sure about MongoHQ but as for PostgreSQL, you can use Heroku Taps to pull the data from the remote database to your local machine. You could then push it to the new app.
Alternatively you could change the environment variable DATABASE_URL of your new Cedar app to point to the database being used by the old app - assuming you're not using the shared database.
This last approach would also work for MongoHq.

Resources