Remote connect to clearDB heroku database

前端 未结 13 1811
故里飘歌
故里飘歌 2020-11-30 18:26

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条回答
  • 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`)
    
    0 讨论(0)
  • 2020-11-30 18:43

    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.

    0 讨论(0)
  • 2020-11-30 18:44

    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.

    0 讨论(0)
  • 2020-11-30 18:46

    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

    0 讨论(0)
  • 2020-11-30 18:46

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

    CLEARDB_DATABASE_URL

    0 讨论(0)
  • 2020-11-30 18:49

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

    0 讨论(0)
提交回复
热议问题