6

I want to use mysql database which is hosted on my own server. I've changed DATABASE_URL and SHARED_DATABASE_URL config vars to point to my server, but it's still trying to connect to heroku's amazonaws servers. How do I fix that?

3 Answers 3

11

According to the Heroku documentation, changing DATABASE_URL is the correct way to go.

If you would like to have your rails application connect to a non-Heroku provided database, you can take advantage of this same mechanism. Simply set your DATABASE_URL config var to point to any cloud-accessible database, and Heroku will automatically create your database.yml file to point to your chosen server. The Amazon RDS Add-on does this for you automatically, though you can also use this same method to connect to non-RDS databases as well.

Here's an example that should work:

heroku config:add DATABASE_URL=mysql://user:password@host/db

You may need to redeploy by making a change and running git push heroku master

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

7 Comments

Did that, but it didn't help. It says in logs that Mysql::Error (Access denied for user 'mydbname'@'ec2-184-72-153-138.compute-1.amazonaws.com' (using password: YES)):
so it uses db_name that I specified in DATABASE_URL, but still trying to connect to amazonaws server
Interesting. I updated my answer to include a password field. Are you specifying that too? I'll continue digging for a bit if so.
yeah, I use a full url with the username and password
the mysql from the string you passed is actually the gem name? And if you needed for example to pass the encoding for the database?
|
3

By the way, the host is XXXX.amazonaws.com, where XXX is a long host hame that probably changes. If you can add a wildcard, that's the easiest %.amazonaws.com

Comments

0

I had this exact same problem with my Dreamhost MySQL database. Turns out the solution was to tell Dreamhost is was Ok to accept connections from this foreign host. Otherwise, Dreamhost blocks all requests to MySQL that don't originate from their systems.

It seems that if Heroku is falling back to Amazon AWS despite your DATABASE_URL, it's because it's being denied access to your MySQL database.

Comments

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.