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?
13 Answers
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
-
17You 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
-
1In 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
-
3you'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
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.
-
4
-
2@BKSpurgeon. I got it to work with phpMyAdmin with the default port (See http://stackoverflow.com/a/22092539/4900327) – Abhishek Divekar Feb 16 '17 at 16:47
-
Thank you so much Mr. It helps me deploy my mysql file to heroku successfully – Travis Le Mar 17 '19 at 10:33
-
@AbhishekDivekar your comment helped me a lot. I just changed the username and some stuff on a congig.inc.php file in my xamp and it worked on PHPMyAdmin. – Ahmed Adewale Dec 03 '19 at 16:15
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

- 12,483
- 8
- 38
- 42
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.

- 1,036
- 1
- 10
- 19
-
I tried this solution but this is not working. But this solution is working fine in Sequal Pro. – nitin.agam Sep 04 '19 at 19:42
-
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

- 3,105
- 11
- 43
- 71
-
4Don't know why this is so heavily downvoted.. your createConnection cleared things up for me. Thanks :) – Nico Mar 30 '16 at 21:41
-
3Reason for down-votes also should be provided. This is the answer that helped me. Thanks, Bro! – Anoop Thiruonam Apr 10 '16 at 16:43
-
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.

- 91
- 1
- 7
-
1You explanation on parts of the clear db database url really helps. Thanks you! – Jur P May 15 '22 at 05:27
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`)

- 1,787
- 2
- 19
- 28
Paste this inside terminal:
heroku config | grep CLEARDB_DATABASE_URL

- 36,322
- 27
- 84
- 93

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

- 442
- 6
- 7
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.
-
4That's good to know, but how does that help the OP find their connection information? – Brad Koch Mar 29 '13 at 13:46
-
1You 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
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.

- 31
- 1
should consider getting the credentials of vars in heroku configurations (Config Vars):
CLEARDB_DATABASE_URL

- 4,325
- 39
- 27
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...

- 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