2

I created a webb app and deployed it at Heroku. So far, so good. Now I need to integrate it with the MySQL database which is located at pythonanywhere.com.

I tried the following command (which is what I managed to find when googling for accessing a remote MySQL database from Heroku):

heroku config:add DATABASE_URL=mysql2://PYTHONANYWHERE_USER:DATABASE-HOST-ADDRESS/DATABASE-NAME--app HEROKU-APP-NAME

Whenever I run this command from the console in Heroku, I get the following message:

bash: heroku: command not found

Have anyone tried connecting to a pythonanywhere MySQL database from Heroku before? Can you show how you did this step-by-step?

The reason why I want to access the PythonAnywhere database (and not just host it on Heroku) is that a lot of the backend is written on PythonAnywhere and stored on that database.

Thanks,

12
  • Have you installed the Heroku CLI? Commented May 14, 2018 at 11:04
  • Also, why are you trying to use a remote database on PythonAnywhere? Heroku has many database addons, including some that provide MySQL. Commented May 14, 2018 at 11:05
  • How do you mean? My app is deployed at Heroku.com and I'm trying to access the PythonAnywhere database from Heroku (in the cloud) Commented May 14, 2018 at 11:06
  • The reason for having the database on PythonAnywhere is that all the backend code is running there. We wanted to have the frontend there as well, but PythonAnywhere lacked support for Node.js projects Commented May 14, 2018 at 11:07
  • The heroku command is the Heroku CLI. You'll have to install it if you want to use it. Commented May 14, 2018 at 11:08

1 Answer 1

1

The heroku command is provided by the Heroku CLI, and should be installed and run from your local machine. Running heroku commands directly from a dyno (e.g., via heroku run bash) won't work.

Once you've set DATABASE_URL using heroku config you should be able to access it from your code via process.env.DATABASE_URL.

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

2 Comments

Thanks Chris! One last question: Do you know what would be the ip in: >>heroku config:add DATABASE_URL=mysql2://username:[email protected]/data_base_name --app heroku-app-name<< I'm not sure that the ip==database host address in PythonAnywhere?
Yes, the hostname should work. Note that all of this is subject to access rules (network-level and database level), so it may not work.

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.