120

How can i perform a remote connect to ClearDB MySQL database on heroku using for example MySQL Query Browser. Where to get url, port, login and password?

roman
  • 5,100
  • 14
  • 44
  • 77

13 Answers13

212

In heroku website, go to My Apps and select the app on which you have installed ClearDB.

On the top corner click on Addons and then select ClearDB MySQL Database. Once there, click on your database and choose the 'Endpoint Information' tab. There you see your username/password. The URL to the database can be acquired by running heroku config --app <YOUR-APP-NAME> in the command line.

In my case, it was something like: mysql://user:pass@us-cdbr-east.cleardb.com/DATABASE?reconnect=true What you need is this part: us-cdbr-east.cleardb.com

Community
  • 1
  • 1
Abbas
  • 3,228
  • 1
  • 23
  • 27
  • 17
    You can also see this directly on the Heroku dashboard/website, just go to your app, click "Settings" and "Reveal config vars". – Eirik H Aug 24 '14 at 21:06
  • 1
    In my case at least, the us-cdbr-east.cleardb.com equivalent part was not the name of the database but rather the name of the host. The database name was however found on the dashboard for the ClearDB addon. – Roseaboveit Jan 27 '15 at 07:23
  • 3
    you'll need to export your local database file to the database created by Heroku. Just follow this video and you'll be good to go https://www.youtube.com/watch?v=mBCH9OTVaGw&t=6s – Kartik Chauhan May 22 '17 at 19:17
105

You run heroku config to get the CLEARDB_DATABASE_URL and it should be something of this format:

CLEARDB_DATABASE_URL => mysql://[username]:[password]@[host]/[database name]?reconnect=true

So basically you just look at your own url and get all you want from there. That's how i set up mysql workbench.

Druid
  • 6,423
  • 4
  • 41
  • 56
Andrei
  • 1,111
  • 2
  • 8
  • 9
35

Paste this command in terminal

  heroku config | grep CLEARDB_DATABASE_URL

After this you will get Database URL. e.g this is your cleardb database URL.

'mysql://b0600ea495asds:9cd2b111@us-cdbr-hirone-west-
 06.cleardb.net/heroku_4a1dc3673c4114d?reconnect=true'

Than this will be your database credentials. (Extracted from Above URL)

USER NAME = b0600ea495asds

PASSWORD = 9cd2b111

HOST = us-cdbr-hirone-west- 06.cleardb.net

DATABASE NAME = heroku_4a1dc3673c4114d

Developine
  • 12,483
  • 8
  • 38
  • 42
21

If you are using mySQL workbench, follow this schema. Go to Heroku > Your Applications Settings > Config Vars, and show the long URL. That url includes your username, password, the URL of the database and the default schema. Paste all of the information as follows below, and you will be able to successfully connect to the database. There was no real explaination on how to connect to ClearDB using mySQL workbench on this thread, so hopefully this helps someone who was struggling.

enter image description here

Jordan Schuetz
  • 1,036
  • 1
  • 10
  • 19
13

I did a video explaining how to connect to MySql using NodeJS on a Heroku server, take a look:

http://www.youtube.com/watch?v=2OGHdii_42s

This is the code in case you want to see:

https://github.com/mescalito/MySql-NodeJS-Heroku

Here is part of the code:

var express = require("express");
var mysql      = require('mysql');
var app = express();
app.use(express.logger());

var connection = mysql.createConnection({
  host     : 'us-cdbr-east-04.cleardb.com',
  user     : 'b6d6c6e874',
  password : 'b3f7###',
  database : 'heroku_1daa39da0'
});

connection.connect();

app.get('/', function(request, response) {
  connection.query('SELECT * from t_users', function(err, rows, fields) {
      if (err) {
        console.log('error: ', err);
        throw err;
      }
      response.send(['Hello World!!!! HOLA MUNDO!!!!', rows]);
    });
});

var port = process.env.PORT || 5000;
app.listen(port, function() {
  console.log("Listening on " + port);
});

CHeers! MAGIC: http://makegif.com/g9yv.gif

lito
  • 3,105
  • 11
  • 43
  • 71
5

Go to your app on heroku and click to the 'settings' tab. Then click the button on the second option that says 'reveal config vars'.

You should find, listed under the CLEARDB_DATABASE_URL variable, something like this...

mysql://[username]:[password]@[host]/[database name]?reconnect=true

So the [host portion] is your host. The [database name] portion is your db name, of course.

You still need your username and password. Go back to the 'overview' tab in heroku. Go to the ClearDB add-on in your installed add-ons section. Click the database you want to access (probably only 1 option there). Click the 'system information' tab. You should see your username and password.

that should be all you need to access your database. I use sequel pro. I just plugged that info (name, host, into the 'standard' tab and I was good to go.

user2364424
  • 91
  • 1
  • 7
3

You can use this one-liner to connect to your MySQL database in your terminal.

$(ruby -e 'require "uri"; uri = URI.parse(ARGV[0]); puts "mysql -u#{uri.user} -p#{uri.password} -h#{uri.host} -D#{uri.path.gsub("/", "")}"' `heroku config:get CLEARDB_DATABASE_URL`)
Sébastien Saunier
  • 1,787
  • 2
  • 19
  • 28
2

Paste this inside terminal:

heroku config | grep CLEARDB_DATABASE_URL
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
2

For Windows users, there is no grep command.

Just try,

heroku config

There is another way, go to settings in Heroku Web. then config var.

0

Yes, you can connect to ClearDB directly, actually I use Workbench to connect. Then you can use the same DB for your localhost and for heroku.

  • 4
    That's good to know, but how does that help the OP find their connection information? – Brad Koch Mar 29 '13 at 13:46
  • 1
    You are right, but I just added an info, because Neil Middleton said "Assuming you can connect to ClearDB directly", then I just said Yes, he can. I apologize for answering something that haven't helped the main question. – Alisson Reinaldo Silva May 15 '13 at 02:58
  • No worries. Things like this are really good comment material, but it looks like you need a few more rep still for that. – Brad Koch May 15 '13 at 03:02
  • i have 0 problems gettig to the heroku service. but from the service to db is where the issue lies. boooo. gettig "dial tcp 127.0.0.1:3306: getsockopt: connection refused" – filthy_wizard Sep 17 '16 at 14:34
0

All of this worked perfectly for me. Using heroku config | grep, as described above and then simply adding another entry into my config.inc.php for use by phpMyAdmin and I can access my cleardb database remotely. It saves me having to have SQL locally and using postgres with Heroku.

GiantCoder
  • 31
  • 1
0

should consider getting the credentials of vars in heroku configurations (Config Vars):

CLEARDB_DATABASE_URL

0

All the details will be in the database URL which can be found in heroku config. Assuming you can connect to ClearDB directly (I've never tried), these should be all you need...

Neil Middleton
  • 22,105
  • 18
  • 80
  • 134
  • not completely. If you're with Spring / Java configuration the docs says "This variable is dynamic and will not appear in your list of configuration variables when running heroku config" and you have to use the command "heroku run echo \$JDBC_DATABASE_URL" in order to retrieve the running configuration. Refs to https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#using-the-spring_datasource_url-in-a-spring-boot-app – CptUnlucky Aug 17 '21 at 17:11