Why isn't mysql
working on Heroku's shell?
Heroku dynos contain your application slug and little else. They're more like Docker containers than traditional servers. If you want to use something in your application, including via one-off dynos like the one you get via heroku run bash
, you need to make sure it's included in your slug.
The mysql
command-line client won't be available by default.
Should I add mysql
to my slug?
I wouldn't recommend it.
Think of your slug as a package for running your application, not a full server. Include what you need to run your application (like a database library for whatever language you're using) and leave extraneous things out.
It's worth noting that there is a maximum size for slugs.
Then how can I access my database?
Instead of running mysql
on Heroku, try running it from your Cloud9 terminal. As long as you use the right parameters for your host, user, password, and port as described in the post you linked to it should connect to your ClearDB database.
The test workspace I set up to try this out already had mysql
installed. In case yours doesn't you should be able to install it. My workspace is based on Ubuntu 14.04:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
On that OS it should be possible to install mysql
by running
sudo apt-get install mysql-client-5.5