roman
roman

Reputation: 5210

Remote connect to clearDB heroku database

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?

Upvotes: 120

Views: 102619

Answers (13)

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.

Upvotes: 2

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

CLEARDB_DATABASE_URL

Upvotes: 0

Jordan Schuetz
Jordan Schuetz

Reputation: 1036

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

Upvotes: 21

GiantCoder
GiantCoder

Reputation: 31

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.

Upvotes: 0

user2364424
user2364424

Reputation: 101

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.

Upvotes: 5

Hammad Tariq
Hammad Tariq

Reputation: 13461

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

Upvotes: 35

Sébastien Saunier
Sébastien Saunier

Reputation: 1877

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`)

Upvotes: 3

Abbas
Abbas

Reputation: 3258

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

Upvotes: 213

user3805474
user3805474

Reputation: 21

Paste this inside terminal:

heroku config | grep CLEARDB_DATABASE_URL

Upvotes: 2

lito
lito

Reputation: 3125

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

Upvotes: 13

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.

Upvotes: 0

Andrei
Andrei

Reputation: 1121

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.

Upvotes: 106

Neil Middleton
Neil Middleton

Reputation: 22240

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...

Upvotes: 0

Related Questions