I want to connect to MySQL attached to the Heroku app from a client such as MySQL Workbench
Get the name of the application you are deploying to heroku. In this case, it is assumed that you have deployed an app called hogehoge. The app name of heroku may be special so that it will not be forgotten or covered, so get it with cli and copy it.
$ heroku list hogehoge fugafuga
Get information about the application hogehoge. The environment variables set in the application are output. In most cases where MySQL is attached to an application on Heroku, the DATABASE_URL should look like this:
$ heroku config -a hogehoge === hogehoge Config Vars CLEARDB_DATABASE_URL: mysql://fizz:[email protected]/heroku_barbarbar?reconnect=true DATABASE_URL: mysql://fizz:[email protected]/heroku_barbarbar?reconnect=true The following is omitted
You can read all of the connection information from the value of the environment variable.
//If the original is below mysql://fizz:[email protected]/heroku_barbarbar?reconnect=true //Read like this mysql://username:[email protected]/schema?reconnect=true //That is, it becomes as follows MySQL host => foo.cleardb.com DB Schema => heroku_barbarbar Username => fizz Password => buzz
That's it. All you have to do is enter the information into your client and connect.
Heroku's default database is PostgreSQL, You can also switch to MySQL. In my case, I often use MySQL regardless of work, private, development environment, or production environment, so I changed from Postgres to MySQL.
If you search for how to change it, you will get as many hits as you want, so go there. By the way, the speed is slow when I access it from the client and use it. Well, it's free, so it can't be helped.